Creating Categorized Views

Create a set of categories for the list of Hybrid Apps. The comment tag associated with this customization is BLACKBERRY_CUSTOMIZATION_POINT_CATEGORIZEDVIEWS.

First, determine names for the categories. SAP recommends that you name the final category “Miscellaneous;” this adds all applications and messages that do not match a category to the Miscellaneous category. Also in this example, all applications that belong to a category must include the category name contained in their display name. For example, an application named “Financial Claim” belongs in the “Financial” category.

There are other ways to determine categories; if you know the names of the applications in advance, you can simply list all the application names that belong in each category.

  1. Open the AppScreen.java file for editing and add:
    import java.util.Vector;
     import net.rim.device.api.util.Comparator; 
  2. Add a list of categories as a private final member variable to the AppScreen class, for example:
    private final String[] m_asHybridAppCategories = { "Financial", "Utilities", "Miscellaneous" }; 
  3. In the constructor of AppScreen, replace the compare method in the Comparator with the following modified version: 
    // BLACKBERRY_CUSTOMIZATION_POINT_CATEGORIZEDVIEWS  
    m_oApps.setSortComparator(new Comparator()   
    {  
    public int compare(Object oApp1, Object oApp2)  
    {  
    return 0;  
    }  
    });  
    Although you can sort with categories, doing so becomes complicated since you must check whether an element is a category name or a Hybrid App, and you typically want to sort only Hybrid Apps within a common category.
  4. Replace the populateList method with this modified version:
    private void populateList()  
    {  
    m_oApps.removeAllElements();  
    Vector vHybridApps = BBHybridAppHelper.getClientHybridApps();  
    for (int i = 0; i < m_asHybridAppCategories.length; i++)  
    {  
    m_oApps.addElement(m_asHybridAppCategories[i]);
    for (int j = 0; j < vHybridApps.size(); j++)
    {HybridApp ha = (HybridApp) vHybridApps.elementAt(j);
    if (ha.getDisplayName().indexOf(m_asHybridAppCategories[i]) >= 0
    || i + 1 == m_asHybridAppCategories.length)
    {m_oApps.addElement(ha);vHybridApps.removeElementAt(j--);
    }
    }
    }
    }  
  5. Replace the drawListRow method in ListFieldCallback with this modified version:
    public void drawListRow(ListField listField, Graphics graphics,   
                                    int index, int y, int width) {       
                            // BLACKBERRY_CUSTOMIZATION_POINT_CATEGORIZEDVIEWS   
                               
                            // y parameter is already offset to center text   
                            int iOffset = (listField.getRowHeight() - getFont().getHeight()) >> 1;   
                               
                            // BLACKBERRY_CUSTOMIZATION_POINT_HYBRIDAPPLIST   
                            // HybridApp oApp = ( HybridApp ) m_oApps.elementAt( index );   
                               
                            // BLACKBERRY_CUSTOMIZATION_POINT_COLORS   
                               
                            final int iMargin = 2;   
                               
                               
                            Object element = m_oApps.elementAt( index );   
                            if( element instanceof HybridApp )   
                           
          {   
                              
            HybridApp oApp = ( HybridApp ) element;   
                               
                               // Draw image   
                              
            EncodedImage oImage = EncodedImage.getEncodedImageResource( "ampicon" + oApp.getIconIndex() + ".png" );   
                              
            Bitmap oBitmap = oImage.getBitmap();   
                              
            graphics.drawBitmap( iMargin, y - iOffset + ( listField.getRowHeight() - oBitmap.getHeight() ) / 2, oBitmap.getWidth(), oBitmap.getHeight(), oBitmap, 0, 0 );   
                              
               
                               // Draw text   
                               graphics.drawText( oApp.getDisplayName(), 2 * iMargin + oBitmap.getWidth(), y );   
                           
          }   
                           
          else   
                           
          {   
                                // element must be a String   
                               String sCategoryName = (String) element;   
                               
               graphics.drawText( sCategoryName, iMargin, y );   
          }
    } 
  6. Replace the navigationClick method in the AppScreen class with this modified version:
    protected boolean navigationClick(int status, int time)   
            {   
                    Field oField = getFieldWithFocus();   
                    if ( oField instanceof ListField )   
                    {   
                            int iIndex = ( ( ListField ) oField ).getSelectedIndex();   
                               
                            if ( iIndex != -1 && m_oApps.size() > 0 )   
                           
          {   
                                   
            Object oElement = m_oApps.elementAt( iIndex );   
                                   
            if( oElement instanceof HybridApp )   
                                    {   
                                       HybridApp oApp = ( HybridApp ) oElement;   
                                      
            XmlHybridApp.startHybridApp( oApp.getModuleId(), oApp.getVersion(), false );   
                                       return true;   
                                    }   
                           
          }   
                    }   
                       
                    return super.navigationClick(status, time);   
            } 
  7. Replace the onHybridAppAdded method in the HybridAppsListener with this modified version:
    public void onHybridAppAdded(HybridApp oHybridApp) {   
                       
            onRefreshRequired();   
                    } 
  8. Save the AppScreen.java file.
  9. Open the CustomizationHelper.java file, which is located in the ...\HybridWebContainer\src\com\sybase\hwc folder and edit the getHybridAppScreenClass() method, to change the class returned to your new class.