Monday, May 30, 2011

Technical Debt

Technical Debt – What it means?

According to Ward Cunningham, technical debt is a culmination of all those internal things in your software that you choose not to do but that can become a major problem in future if left undone. These little issues that are often postponed are not visibly prominent issues.

The software program or the application might seem all perfect with high quality but in true sense, the application is all good superficially. These problems are hidden and only a proper scrutiny of the software system will help recognize them. While the Quality Assurance team (QA) might say that the application has quality and a few defects, the technical debt still prevails. If this technical debt is not managed or reduced at the right time, chances are that it will eventually increase the cost of writing/ maintaining the code. This will outweigh its benefit or value to the end consumer.

Technical debt is more or less like a credit card that keeps on adding to the outstanding balance at a very high rate of interest. In case of technical debt however, the costs don’t indicate money but the time and efforts needed to work around the problems. In simpler terms, the more time the team takes to pay off the technical debt i.e. work around to solve the little underlying problems, the more the interest is accumulated in the form of additional workarounds. This will ultimately cause the business to suffer with higher costs.

Truly speaking, the technical debt might not really involve money but it actually can cause financial losses. That’s because the time and effort the developers spend on cracking the code to solve the problem can be spent more productively to add value to the business. The codes are often quite complicated making it again very difficult to find the bugs. This time-consuming process leaves the developers with less time to work on something more valuable hence causing the business and the organization on a whole to suffer financially.

Why does Technical Debt get accumulated?

In the initial phase, writing a code is quicker because the developers write codes without tidying up, without writing unit tests and without doing any Test Driven Development. Hence, the team churns out more number of stories in relatively less time. Writing software requires them to give a decent amount of time for it`s development. A software development process requires working on different levels. It involves addressing the problem as they show up in a case to case basis. However, the underlying problems don’t show up quickly. Doing the right thing, the right way takes more time, especially in the beginning.

Where does the Technical Debt come from?

• Inexperienced developers: Software developer has to constantly upgrade his or her skill set depending on the market trends. This seldom happens. As a matter of fact, many developers write codes for languages like JAVA or C# or Ruby without having the basic knowledge of what a good Object Oriented Code is. As a result, they end up writing codes that are inappropriate or are typically meant for languages they are familiar with like Visual Basic, etc. The onus for this lies on the company too. Many a time’s companies in order to maximize their profits use code developers who are inexperienced i.e. cheap. This practise in turn effects the code and at the end the reputation of the company and hence must be avoided as much as possible.

• Deadline pressure: The pressure of delivering the product within a stipulated time is often a reason for several little underlying problems go unnoticed. Due to their commitment to release the program or application of iteration on a specified date, the developers overlook minor errors and expedite things. These minor errors can in future become major ones causing the application to become unresponsive. Unfortunately, the management also supports the developers without realising that it could end up in high managerial costs.

• Untidy, hard-to-read code: When the code that is initially written is not a tidy one, the next developer who works on it will also not feel compelled to tidy it up or write a clean code himself. This results in a small mess becoming bigger every time a new developer works on it.
• Specialisation: When a code is a specialized one, the developers often back out even if the find that code is a bad one. One, they don’t feel qualified to work on that code and secondly, they don not want to take any extra effort of tidying up a specialized code.

• Over complication: Software developers often tend to over complicate things in order to stay safe from any future problem. They try to visualize the problems that may arise and try to develop codes for such potential problems. In this way, they end up writing codes that go in an entirely different direction without giving them any benefit. Many a times, the code doesn’t really fit the need as it is for a problem that doesn’t even exist. Over design and over complication often takes extra time and effort without any use.

• Over simplification: Contrary to poplar belief over simplification can be also a major cause for a software`s downfall. Software developers sometimes in order to avoid writing excess code language for a program sometimes make the program over simplified which can turn out be just as bad as the point given before this ‘over complication. Sometimes due to this over simplification the software fails to perform when set a little different set of parameters. Software must be flexible enough to be able to cope with at least a decent change of the kind of data. So it highly important that a kind of balance is maintained between the two above points which is actually essential for the success of any software.

• Bad design: Some codes are simply designed poorly. Building on a poorly designed code or working on the code without tidying it up makes the problem even worse.

Finding a solution to the problem

There is no one certain way to solve the problem. As a matter of fact, the solution will take several iterations. It is important to show a level of patience and adopt a multi-pronged approach to reach the solution. Some of the methods have been discussed in brief below.

Planks in the solution:

1. The basic step to solve the problem is to first train the developers in the language that is to be used. Only a proper understanding of the language will help the software developers to write a code that is less prone to have any inherent problems. Also, in order to be successful, it is essential that the trained developers are tested and supported by the pros in that area so that the training results to be effective.
2. The developers and the managers have to be informed about the current problems. Also, the impact of these problems on the business costs has to be ascertained in order to know the significance of the problems. This will clearly indicate the level of problem and the value of solving the problem. The management should also make it clear that it acknowledges the problem and is prepared to start paying off the technical debt that has inevitably arisen.
3. The training sessions on the code smells, Refactoring, Unit Test, Test driven Development have to concisely deal with the inherent problems and aim at reaching a solution. A combination of classroom sessions, web based books and material will enhance the training.
4. The software developers should be given some time (at least 2 hours a week) from their office hours to practice their skills. This practice should be on throw-away codes so that the developers can experiment and come up with new ideas of solving a problem. Time to practice and study is perhaps the best way to diagnose a problem and make the developers confident for solving it in real-time.
5. Using tools such as static analysis, Unit test, continuous integration, and automated acceptance tests helps the teams find, reduce and measure their technical debt load. However, measuring this should not imply that the team will be punished or rewarded for the results. If that happens, even these figures can be manipulated and the end result will only be destructive for the Company.
6. Developers who had undergone and successfully completed their training and also show a visibly higher level of proficiency in their skills should be rewarded. They could be given some token gifts instead of money as such things will give them some recognition and motivate others to develop.
7. Bi-weekly meetings should be conducted over lunch to help the developers meet and discuss the various technical issues that they face. The lunch often helps in getting more attendance and the more the developers, the more technical issues will be solved. Also, people form the senior management should also randomly attend these meets to indicate the support of the management to the software developers.
8. Lastly, a technical debt backlog should be maintained that has records of any technical debt that arises. Whenever a technical issue is reported that can’t be addressed immediately, the developer should be asked to write a Technical Debt card. This will help the Company track the Technical Debt and prioritize its work accordingly.


As is clear from the above, every business has a situation that consists of a problem and an opportunity. The success of the organization hence, lies on how it deals with the problem and how it cashes in on the opportunity.

The Problem: The crux lies in the technicalities of the codes that are developed by the software developers. The code bases of the projects are accumulating technical debt. This has made the entire system to slow down. This basic problem is costing the business financial losses as the valuable time and efforts of the developers is wasted in trying to fix the bugs that arise due to the technical debt.

The Opportunity: With the technical debt becoming prominent, the company has a reason to improve the technical skills of its developers which will in turn help the company to develop new products and deals with the technical issues in-house.
, , , ,

Sunday, May 29, 2011

Is NFC the Future of Mobile Payment ?

Last week, Google unveiled Google Wallet in a joint venture with Mastercard. The initiative will allow customers to pay for goods by waving their mobile phones at check-out terminals.

In the past few thousand years, the way we pay has changed just three times—from coins, to paper money, to plastic cards. Now many believe we are on the brink of the next big shit. Mobile Payment based on NFC Technology. But can NFC really become the future of mobile payment ?


In order to be the De Facto standard of mobile payment, NFC would certainly have to overcome a few obstacles as well as stand up to challenges from other technologies in the field of mobile-payments. A major obstacle for NFC phones is that in order to function as a payment tool the merchants would need to upgrade their POS readers.

In New York and San Francisco some of the merchants like Macy’s, Subway and American Eagle Outfitters have done the necessary upgrades thus allowing their customers with Nexus S phone to make payments through phones in these cities. However NFC still faces a big challenge of convincing the phone manufacturers to put NFC chips in their phones. The manufacturers on their part would be skeptical about using NFC chips until more merchants upgrade their POS terminals to handle NFC payments. On the other hand even the retailers might not be open to the idea of spending more money on upgrades until more number of consumers begins to use NFC enabled phones.

There are one or more biometric technologies which might offer some kind of challenge to NFC. Few of leading companies in that field like Square are planning to offer a new system which enables customers to pay simply by stating their names. In order to avail this service you need to register with the merchant wherein you will have to provide your credit card details. However, when you enter a shop, all you need to do is to state your name in order to pay for your purchases. This concept can be extended in future, where you can make payments through MasterCard or Visa by registering your voice with them. With advanced voice recognition technologies available these days, it wouldn’t be completely farfetched to think that sometime in future it might be possible to make payments by simply stating your name, address and the purchase amount into the microphone at the sales counter which would verify your identity against your registered voiceprint. It could be extended, for added security, with a camera transmitting your image along with your voice for facial recognition.

Though NFC is surely gaining popularity as a payment device, it’s the users who will give the ultimate verdict on which technology will win in the long run. It will depend on what the customers find more user-friendly and convenient. With many other several tasks that the mobile phones already perform, Mobile use as payment device might just become another one of them.
,,,,,

Thursday, February 24, 2011

Using Styles, Themes, and Painters with LWUIT







Contents
  • Style
  • A Style for Each State
  • Using Style
  • The Theme Creator
  • UIID
  • Spinner
  • Table
  • Conclusion
  • Resources
Lightweight User Interface Toolkit (LWUIT) version 1.3, released in December 2009, consolidates the modifications over version 1.1 initiated in version 1.2 and incorporates some new ones too. It also introduces three new components -- Tree, Table and Spinner. The use of the Tree widget is demonstrated through the LWUIT Demo that comes with the LWUIT download bundle. In this article we examine the changes with respect to Style and go on to check out Table and Spinner.
The demo applications have been developed on the Sprint Wireless Toolkit 3.3.2 (SWTK). Not only does this toolkit support LWUIT extremely well, it also has an interesting array of device emulators like those for HTC Touch and Samsung Instinct. If you intend to try out LWUIT, I would strongly suggest that you install the Sprint WTK on your computer.

Style

The idea behind Style is to centrally define the visual attributes for each widget (component). In addition to its physical design, such as its shape, the appearance of a widget can be defined in terms of a number of common features or attributes. In LWUIT 1.1 the settable attributes for a component were:
  • Background and foreground colors.
  • Fonts for writing text on it.
  • Background transparency.
  • Background image.
  • Margin and padding.
  • Background painters.
  • Border.
The additional attributes defined under LWUIT 1.3 are:
  • Background type -- specifies whether the background has an image or a color gradient. An image can be tiled, scaled or aligned (unscaled with alignment). A gradient for background can be linear (vertical/horizontal) or radial.
  • Background alignment -- if an image (tiled or aligned) is used for the background, the alignment (top/bottom/left/right/center) is defined by this attribute.
  • Background gradient start and end colors.
A Style object holds all these attributes for each state of each component that is used in an application, and has appropriate accessor methods. In addition this class also has the ability to inform a registered listener when a style object associated with a given component is altered.

A Style for Each State

In the early days of LWUIT, that is up to version 1.1, there used to be just one Style object for each widget to be displayed. This single Style object had separate attributes corresponding to the different widget states. For example, the background color for the unselected (unfocused) state would be defined as bgColor and that for the selected (focused) state as bgSelectionColor. The code for setting these colors would look like this.
 
        //when the widget does not have focus
        //the background will be red
        myComponent.getStyle().setBgColor(0xff0000);
 
        //when the widget has focus
        //the background will be blue
        myComponent.getStyle().setBgSelectionColor(0x0000ff);
 
However, as of version 1.2, this has changed. Components now have distinct styles for each of their permissible states. Most components would have a selectedStyle and an unselectedStyle. Components like buttons and those that extend the Button class will have an additional style corresponding to the pressed state -- the pressedStyle. So, the above code sample will now look as follows.
 
        //when the widget does not have focus
        //the background will be red
        myComponent.getUnselectedStyle().setBgColor(0xff0000);
 
        //when the widget has focus
        //the background will be blue
        myComponent.getSelectedStyle().setBgColor(0x0000ff);
 
Note that we have used two different versions of the getter method -- one for each style. Actually, the Component class has a getStyle method too, which returns the appropriate style depending upon the state of the component. This capability leads to simpler coding especially for methods that render components.
When a component is created, a default Style object gets associated with it as its unselectedStyle. The other styles are created when accessed for the first time through the corresponding setter or getter methods.
There are several ways for setting and modifying attributes as shown in the following list.
  • By using the get*Style().set* combination as above.
  • By creating a new style with the desired attributes and then invoking the set*Style method to set the new style.
  • Style for an entire set of widgets can be set through the UIManager instance. The relevant technique is
·          
·                 //method for setting unselected style
·                 UIManager.getInstance().setComponentStyle
·                         (String id, Style style)
·          
·                 //method for setting selected style
·                 UIManager.getInstance().setComponentSelectedStyle
·                         (String id, Style style)
·          
However, currently this approach works for selected and unselected styles.
  • Through a Theme.
In the following section we shall check out a simple demo application which shows how styling can be done under LWUIT 1.3.

Using Style

Our application will have a single form with three widgets and will look like the Figure 1:





















Figure 1. Style Update Demo.
The screenshot above shows a screen with two labels and one button. Labels, by default, cannot receive focus and the topmost widget is such a label. The second label has been explicitly made focusable as shown by the code snippet below.
 
        //create a label
        Label focusLabel = new Label("Focusable");
 
        //and make it focusable
        focusLabel.setFocusable(true);
 
In Figure 1 we see the second label in the selected state. The applicable style is set as follows:
 
        //modify default style to set attributes 
        //for selected state of focus label
        focusLabel.getSelectedStyle().setBgColor(0x555555);
        focusLabel.getSelectedStyle().setFont(font);
        focusLabel.getSelectedStyle().setBorder
                (Border.createBevelRaised());
 
The first label and the button are unselected and their appearances are styled through the same Style object. This object has the following attributes:
 
        //create a common style for unselected state
        Style unselStyle = new Style();
        unselStyle.setFont(font);
        unselStyle.setBgTransparency(64);
        unselStyle.setFgColor(0xffc605);
        unselStyle.setBorder(Border.createEtchedRaised());
 
This style is set as the unselected one for all labels by calling the setComponentStyle(String id, Style style) method. This is shown below.
 
        //set unselected style for labels
        UIManager.getInstance().setComponentStyle
                ("Label", unselStyle);
 
The unselected style for the button is set in the following way using the same style object that is used for labels.
 
        //create button
        Button button = new Button("Button");
 
        //set style for unselected state of button
        button.setStyle(unselStyle);
 
Figure 2 shows the same screen as above with the button in the selected state.





















Figure 2. The button is selected.
We can see that both labels are unselected and their appearances are the same. The button, which has focus, looks just like focusLabel in Figure 1. This is ensured by creating a style with attributes that have the same values that were used for the selected style of focusLabel. This new style -- buttonSelStyle -- is then installed as the selected style for the button.
 
        //create selected style for button
        Style buttonSelStyle = new Style();
        buttonSelStyle.setBgColor(0x555555);
        buttonSelStyle.setFont(font);
        buttonSelStyle.setBorder(Border.createBevelRaised());
        ...
        //set style for selected state of button
        button.setSelectedStyle(buttonSelStyle);
 
In a similar manner we create and set a style for the pressed state of the button:
 
        //create pressed style for button
        Style buttonPrStyle = new Style();
        buttonPrStyle.setBgColor(0xff0055);
        buttonPrStyle.setFont(font);
        buttonPrStyle.setBgTransparency(127);
        buttonPrStyle.setBorder(Border.createRoundBorder
                (12, 5, 0xff0000));
        ...
        //set style for pressed state of button
        button.setPressedStyle(buttonPrStyle);
 
The result of pressing the button can be seen in Figure 3 below.





















Figure 3. The button is pressed.
In the demo application above, style attributes have been set programatically to show some fundamental aspects of styling. In real life applications, though, it would be advisable to apply themes.

The Theme Creator

In the beginning there was the Resource Editor -- a very handy tool for creating and editing resource files. In Decemeber 2008 it was renamed LWUIT Designer, and in the latest release it has become the Theme Creator. While the essential functionality remains the same, both the LWUIT Designer 1.2 and the Theme Creator allow the creation of three distinct styles, as we can see in Figure 4.



















Figure 4. Creating a theme with three styles.
The Theme Creator now provides support for SVG images too. This is shown in Figure 5.





















Figure 5. SVG support.

UIID

Every component can have its own unique id which is used for styling as we have seen. All components in the library have their ids. When creating a custom component, a new id should be alloted. Sometimes, components are built up using existing ones and these constituent parts can have ids different from their original ones. Consider the case of a component that uses a label to form a part. If we want to give this part a distinct id for styling, the getUIID method of Component class would have had to be overridden in the days of LWUIT 1.1. A new method -- setUIID -- was provided in LWUIT 1.2 to do the same thing in a simpler and more intuitive way. So now we can write:
 
        Label newMyPart = new Label();
        newMyPart.setUIID("NewMyPart");
 

Spinner

A spinner is similar to a combo box in the sense that it shows a single value from a list of values. However, spinner does not show a drop down list for selection. Instead the up or down key has to be used to scroll through the list. Also, a spinner can show only a date, time or numerical value. Figure 6 shows a form with two components: a button and a spinner. The button has been added to show how different styles take effect depending on whether the spinner has focus or not. Here the spinner is shown in the unselected state.





















The Spinner class does not have an accessible constructor. One of the factory methods has to be used to get an instance of spinner. In this case we create a spinner to display time in twenty-four hour format showing hours, minutes and seconds. The method used is: createTime(int min, int max, int currentValue, int step, boolean twentyFourHours, boolean showSeconds). The first two parameters specify the minimum and maximum values for the list. The third parameter defines the value to be shown initially. The unit for all the three is seconds since midnight. The fourth is the difference between two successive values in seconds. The fifth and sixth parameters define the display format.
The image on the right of the time display is called the spinnerHandle and is meant to indicate that the display can spin. The following code snippet shows how the spinner is created and the spinnerHandle is set. A word about the value initially shown in Figure 6 above: while creating the spinner instance, the value specified for initial display is 180, which corresponds to three minutes or, in the given format, 00:03:00. However, note that the step size has been specified as 40 which means 180 is not in the list. The time displayed corresponds to 160 which is the highest value not exceeding 180.
 
        //create spinner with seconds display
        spinner = Spinner.createTime(0, 7200, 180, 40, true, true);
 
        //set image to visually indicate it is spinnable
        try
        {
                spinner.setSpinnerHandle(Image.createImage("/handle.png"));
        }
        catch(java.io.IOException ioe)
        {
        }
 
In Figure 6 we see the spinner in the unselected state. There is a dark olive green background on which the numerical display is rendered in blue. The background represents the spinner container and its unselected appearance is set as follows:
 
        //affects look when spinner does not have focus
        spinner.getUnselectedStyle().setBgColor(0x556b3f);
        spinner.getUnselectedStyle().setBorder(Border.createBevelRaised());
 
The first step in setting style for the time display is to get the DefaultListCellRenderer instance for the spinner. The style attributes can then be set as shown below.
 
        //create a font
        Font font = Font.createSystemFont(Font.FACE_PROPORTIONAL,
                Font.STYLE_BOLD,Font.SIZE_LARGE);
 
        ...
 
        //affects look when spinner does not have focus
        spinner.getUnselectedStyle().setBgColor(0x556b3f);
        spinner.getUnselectedStyle().setBorder(Border.createBevelRaised());
 
        ...
 
        //renderer for the cell containing display
        DefaultListCellRenderer dlcr = 
                (DefaultListCellRenderer)spinner.getRenderer();
 
        //affects steady state look
        dlcr.getSelectedStyle().setBgColor(0x0000ff);
        dlcr.getSelectedStyle().setFgColor(0);
        dlcr.getSelectedStyle().setFont(font);
        dlcr.getSelectedStyle().setPadding(Component.RIGHT, 7);
 
        //affects look during scrolling
        dlcr.getUnselectedStyle().setBgTransparency(0);
        dlcr.getUnselectedStyle().setFgColor(0);
        dlcr.getUnselectedStyle().setFont(font);
 
The code above also sets the renderer style for the unselected state. This style becomes effective when the spinner value scrolls. To see how that works, press the down key. Now, the spinner gets focus and its appearance changes as specified by the code below.
 
        //affects look when spinner has focus
        spinner.getSelectedStyle().setBgColor(0x0000ff);
        spinner.getSelectedStyle().setBorder
                (Border.createRoundBorder(12, 5, 0xff0000));
 
The spinner now looks like what's shown in Figure 7.






















Figure 7. Spinner is selected.
Although the spinner now has focus, it will not respond to the up or the down key. At this stage the scrolling keys will toggle focus between the spinner and the button. To direct the scrolling key events to control the spinner display, the select key has to be pressed while the spinner has focus. Generally speaking, the select key can be used to toggle the applicability of scrolling keys between a form itself and a component with focus contained in the form. The scrolling keys can now be used to sequentially change the time displayed.
What remains now is to see how we can retrieve the value selected on the spinner. The demo does this in different ways. One way is through a command. We add the Show command to the form and, in the actionPerformed method, call into the getValue method of Spinner class.
 
        //create and add 'Exit' command to the form
        //the command id is 1
        demoForm.addCommand(new Command("Exit", 1));
 
        //create and add command to show spinner value
        //the command id is 2
        demoForm.addCommand(new Command("Show", 2));
 
        //this MIDlet is the listener for the form's command
        demoForm.setCommandListener(this);
 
        ...
 
        //act on the commands and the click
        public void actionPerformed(ActionEvent ae)
        {
                Command cmd = ae.getCommand();
 
                if(cmd != null)
                {
                        switch (cmd.getId())
                        {
                                //'Exit' command
                                case 1:
                                notifyDestroyed();
                                        break;
 
                                //'Show' command
                                case 2:
                                System.out.println("Value 
                                                shown through command : " 
                                                + spinner.getValue());
                        }
 
                        return;
                }
 
                ...
        }
 
A second method is to register the MIDlet as the ActionListener for the spinner. If we now click on the spinner, the actionPerformed method of the MIDlet will be invoked. The necessary action can then be taken.
 
        
        //this MIDlet is the action listener for spinner
        spinner.addActionListener(this);
 
        ...
 
        //act on the commands and the click
        public void actionPerformed(ActionEvent ae)
        {
                Command cmd = ae.getCommand();
 
                if(cmd != null)
                {
                        ...
 
                        return;
                }
 
                if(ae.getSource() == spinner)
                {
                        System.out.println("Value shown on click : "
                         + spinner.getValue());
                }
        }
 
The third approach used in the demo is to add the MIDlet to the spinner as the SelectionListener. For this technique to work, the MIDlet has to implement the SelectionListener interface so that its selectionChanged method is called whenever the spinner selection is changed.
 
        //this MIDlet is the selection listener for spinner
        spinner.addSelectionListener(this);
 
        ...
 
        public void selectionChanged(int oldSelected, int newSelected)
        {
                if(oldSelected != newSelected)
                {
                        ListModel model = spinner.getModel();
                        System.out.println("Selection changed from " + 
                                model.getItemAt(oldSelected) + " to " +  
                                model.getItemAt(newSelected));
                }
        }
 
When we click on a list, its selection changes, and this causes the selectionChanged method of the registered SelectionListener to be called in addition to the actionPerformed method of its ActionListener. As Spinner is a subclass of List, it behaves in a similar fashion and clicking on it results in the printing of the selection change message for the demo. For a spinner, however, we do not consider this to be a valid selection change since the value remains the same. The if clause in the above code listing takes care of this issue. The resultant console printouts for all three approaches are shown in Figure 8.











Figure 8. Message printouts.

Table

A table displays information in the form of a grid. The topmost row describes the name of the data in each column. These are the Headers. The rest of the table displays data and is comprised of Cells. The headers are instances of Label and are meant to be uneditable. The cells can be either editable or uneditable. Editable cells are instances of TextField while uneditable cells are instances of Label. However, uneditable does not mean unmodifiable as we shall see when we discuss the demo application.
Figure 9 shows a table with 5 rows and 3 columns. The topmost row holds the headers. The rest of the rows hold cells that display data. Here we have two kinds of data: text in the leftmost column (column 0) and numbers in the other columns (columns 1 and 2).





















Figure 9. A table.
The contents of a table are determined by an underlying model -- the table model. LWUIT defines the TableModel interface that must be implemented by a table model; the default implementation included in the library is the DefaultTableModel class. So the first step in creating a table is to set up the model. This model is then passed as a parameter to the table constructor. The relevant code for our application is:
 
        //define headers
        String[] columns = new String[] {"Items", "Good", "Scrap"};
 
        //define data
        Object[][] data = new Object[][] {{"Plate-01", 
                new Integer(1605), new Integer(57)}, {"Plate-02", 
                new  Integer(5001), new Integer(326)}, {"Coil-01", 
                new Integer(417), new Integer(124)}, {"Coil-02", 
                new Integer(451), new  Integer(22)}};
 
        //create model with uneditable cells
        //as specified by last parameter
        //for editable cells last parameter must be 'true'
        DefaultTableModel model = new DefaultTableModel(columns, 
                data, false);
 
        //create table
        table = new Table(model);
 
The cells of our table are labels and the default alignment is Label.LEFT. There is a method in the Table class to set cell alignment -- setCellAlignment. However, this is not a static method and works only for new cells created for an existing table. The default alignment for headers is Label.CENTER To change the alignment of cells, we need to access each label that forms a cell and set its alignment. Another point to be noted is that, for some form layouts, the sizing of the last column may not work properly. We have used a kind of rendering prototype to ensure proper sizing. All this is shown in the code snippet below.
 
        //create a font
        Font font = Font.createSystemFont(Font.FACE_PROPORTIONAL,
                Font.STYLE_BOLD,Font.SIZE_LARGE);
 
        //width of 'rendering prototype'
        int w = font.stringWidth("WWWW");
 
        ...
 
        //does not affect alignment of cells already created as
        //table is constructed with cells with default alignment
        //works only for cells created later
        //this happens, for example, if new data is set
        table.setCellAlignment(Label.CENTER);
 
        TableLayout layout = (TableLayout)table.getLayout();
        Component c = null;
 
        //'getRowCount' does not take into account the header row
        //so add 1 to get total number of rows
        int rows = ((DefaultTableModel)table.getModel()).
                                getRowCount() + 1;
        int cols = ((DefaultTableModel)table.getModel()).
                                getColumnCount();
 
        for(int i = 0; i < rows; i++)
        {
                for(int j = 0; j < cols; j++)
                {
                        //get the component for cell at
                        //specified row and column
                        c = layout.getComponentAt(i,j);
 
                        if(i == 0)
                        {
                                //set border for headers
                                c.getUnselectedStyle().setBorder
                                        (Border.createLineBorder
                                        (1, 0xff0000));
                                if(j == cols - 1)
                                {
                                        //use prototype
                                        //to size the last column
                                        c.setPreferredSize(new Dimension(w, 
                                                c.getPreferredH()));
                                }
                        }
                        else
                        {
                                //necessary because cells were originally
                                //created with default (left) alignment
                                ((Label)c).setAlignment(Label.CENTER);
                        }
                }
        }
 
The header strings and the cell data are held within the table model. The TableModel interface defines methods to access these variables. Note that there is only a getter method for the column names while there is a getter as well as a setter method for the cell values. The Show command on our demo form uses the getValueAt method to print out a cell value on the console.
 
        //act on the commands
        public void actionPerformed(ActionEvent ae)
        {
                Command cmd = ae.getCommand();
 
                switch (cmd.getId())
                {
                        ...
 
                        //'Show' command
                        case 2:
                                //get the table model instance
                                DefaultTableModel dtm = 
                                        (DefaultTableModel)
                                        table.getModel();
 
                                //get the value at the specified cell
                                //use actual row number - 1 
                                //since actual first row is not for data
                                Object val = dtm.getValueAt(0, 2);
 
                                //print value
                                System.out.println
                                        ("Plate-01 Scrap : " + val);
 
                                ...
 
                }
        }
 
The printout is shown in Figure 10.












Figure 10. Accessing cell data.
The setValueAt method can be used to programatically change data in a cell -- even for uneditable cells. In our demo application the Show command is replaced with a Modify command which changes the data in the cell for Plate-02 Scrap from 326 to 750. The setValueAt method leads to the creation of a new label to replace the existing one. As we have already set cell alignment to Label.CENTER, the new value remains properly aligned.
 
                //create and add command to show value
                //the command id is 2
                //demoForm.addCommand(new Command("Show", 2));
 
                //create and add command to change value
                //the command id is 2
                demoForm.addCommand(new Command("Modify", 2));
 
                ...
        }
 
        ...
 
        //act on the commands
        public void actionPerformed(ActionEvent ae)
        {
                Command cmd = ae.getCommand();
 
                switch (cmd.getId())
                {
                        //'Exit' command
                        case 1:
                                notifyDestroyed();
                                break;
 
                        //'Show' command
                        /*case 2:
                                //get the table model instance
                                DefaultTableModel dtm = 
                                        (DefaultTableModel)
                                        table.getModel();
 
                                //get the value at the specified cell
                                //use actual row number - 1 
                                //since actual first row is not for data
                                Object val = dtm.getValueAt(0, 2);
 
                                //print value
                                System.out.println
                                                ("Plate-01 Scrap : " 
                                                + val);*/
 
                        //'Modify' command
                        case 2:
                                //get the table model instance
                                DefaultTableModel dtm = 
                                        (DefaultTableModel)
                                        table.getModel();
 
                                //set the value at the specified cell
                                //use actual row number - 1 
                                //since actual first row is not for data
                                dtm.setValueAt(1, 2, new Integer(750));
                }
        }
 
In Figure 11 we can see the new value for Plate-02 Scrap.






















Figure 11. Cell data modified.
In the demo application for table, the only styling done programmatically is for the set of borders for the headers. The rest of the styling has been defined in a theme. The theme file is shown below in Figure 12. A word of caution here. This theme file has been created by the Theme Creator that comes with LWUIT 1.3. The Resource Editor that comes with the SWTK is of an earlier vintage and will not be able to open this file.















Figure 12. Theme file for the demo app.

Conclusion

We have seen how the approach to styling has been modified since LWUIT 1.1. We have also checked out the new Theme Creator and two new components that have been introduced in LWUIT 1.3. However, there are a number of interesting new features that have not been discussed here. These are listed in What's new in This Release in the LWUIT 1.3 download bundle.

Resources

  • src_codes.zip -- source code and resources for the demo applications.
  • LWUIT 1.1 for Java ME Developers -- useful for a detailed introduction to LWUIT basics as most of the fundamentals remain valid for LWUIT 1.3.
  • Lightweight User Interface Toolkit (LWUIT) project home -- has a link for source code and for download.
  • Shai Almog's blog on Java & LWUIT

Source: http://today.java.net/article/2010/04/19/using-styles-themes-and-painters-lwuit
----------------------------------------------------
If you search for Software outsourcing Company, Symbyo Right Sourcing™ is a unique approach to outsourcing that offers the best of both worlds by blending onsite, onshore and offshore resources and locations into one smooth global delivery model.
Symbyo offers Oracle Consulting and Microsoft .NET Consulting services, Offshore Oracle outsourcing services and Microsoft .NET Development services and offshore .Net outsourcing services.

,,,,

Monday, January 24, 2011

Can I Use this Intent in Android?



Android offers a very powerful and yet easy-to-use message type called an intents. You can use intents to turn applications into high-level libraries and make code modular and reusable. The Android Home screen and AnyCut applications, for instance, use intents extensively to create shortcuts.

Thursday, January 13, 2011

Lwuit for blackberry and android


This document is not supposed to be a guide for LWUIT . I want to provide some information for interested LWUIT programmers to extend their reach to the BlackBerry and Android platforms. If you have never worked with these targets before, don't forget to read some of the available developer documentation. There is way too much important information to put into one place. But this document should help you by giving a working example and providing links to other resources along the way.
I won't go into much detail on how to install and use the required software tools. Please read the documentation that comes with each software and search the Web, or ask for help in a forum. I assume that you already use an IDE like Netbeans or Eclipse. So you do not have to run the build scripts from the command line and can just integrate them into your projects. To improve your efficiency you probably want to install a BlackBerry/Android plugin for your IDE. If you do that, you do not have to use the scripts that I provide here. But they can give you an idea about the build procedure.

The ANT scripts copy all the source files to a separate directory and compile your application there. This allows you to use separate library-type projects within your IDE environment and use the scripts to put the pieces together.

I have taken a sample application from the LWUIT blog and modified it a little. First download the sample application sources and the build files . The archive contains the application itself and two ANT scripts, one for each platform. You still need to get the LWUIT sources and the LWUIT implementations for BlackBerry and Android from the Subversion repositories . You really should get up-to-date copies from the repository and not the LWUIT binaries.

Building for BlackBerry

The LWUIT blog describes in detail how to build LWUIT applications for BlackBerry with Netbeans. That is a very nice step-by-step guide to get going with Netbeans and an alternative to the approach that I take here.

Install first:

Apache ANT
bb-ant-tools

Antenna
SUN WTK 2.5.x
BlackBerry JDE 4.3 and 4.7

There are two LWUIT implementations for BlackBerry right now. This ANT file uses the official implementation. The sources can be found in the BlackBerry subdirectory within the LWUIT Subversion repository . I have my own implementation in the LWUIT-Incubator that you could use, but you would have to do a few adjustments. In the long run there is going to be only the official one.

The build file compiles your application for the BlackBerry Operating Systems version 4.3.0+ and for 4.7.0+. Read the BlackBerry developer documentation about BlackBerry OS versions and compatibility issues. The 4.7.0 build will run on touch screen and non-touch screen devices that run BB OS 4.7 or later.

You need to configure the variables within the 'ADJUST THIS TO YOUR ENVIRONMENT' comments. And you need to adjust the 'getsources_430' and 'getsources_470' targets. These targets copy all the source and binary files from your project locations to a temporary directory. Make sure to copy the LWUIT sources, the LWUIT BlackBerry implementation sources and the application sources into one directory. The same has to be done for any binary files that you might need for your application.

Finally run the 'buildblackberry' target to build the files. If you run the script from the commandline type:
ant -f build_blackberry.xml buildblackberry

If everything works as expected you will end up with a lot of files in the 'bb_bin_430' and 'bb_bin_470' directories. You only need the ALX/COD file pair for installation using the BlackBerry Desktop Manager and the 'bb_bin_430/smallcod' and 'bb_bin_470/smallcod' directory contents for OTA installation.

The ANT script does not include obfuscation and signing, but it can easily be added. Obfuscation might not be that important as the BlackBerry build process already provides some level of obfuscation.

To see how the sample looks you can install it OTA on your BlackBerry by using the proper link below:
For BB OS 4.3 and later:
lwuitlist.jad (No touch screen support)
For BB OS 4.7 and later:
lwuitlist.jad (With touch screen support)

Building for Android

Install first:

Apache ANT
Android SDK 2.0 or later

Note that signing your application for Android is mandatory. The good news is that it is free, you can use your own certificates.

The ANT file builds your application for Android OS 1.5 and later. It should work on any future device, provided that you design your application to work with any resolution, touch screen or no touch screen, hardware keyboard or not, screen density, ... . LWUIT gives you the tools to do that, it's up to you to use them.

Configure the variables within the 'ADJUST THIS TO YOUR ENVIRONMENT' comments. Additionally you need to adjust the 'getsources' target. This target should copy all the source and binary files from your project locations to a temporary directory. Copy the LWUIT sources, the LWUIT Android implementation sources and the application sources into one directory. The same has to be done for any binary files that you might need for your application.

If you run the script from the commandline type:
ant -f build_android.xml buildandroid

In the end you will have an APK file within your 'android_bin' directory that you can use to install on the emulator or on real devices.

To see how the sample looks you can install it OTA on your Android device or emulator by using the link below:
For Android OS 1.5 and later:
http://www.pader-sync.com/LWUITList.apk

Source: http://www.pader-sync.com/lwuit-for-blackberry-and-android.html
____________________________________________________________________
If you need Software outsourcing Company Contuct Us


,,,,