Creating a Gallery View

Change the Mobile Workflow Package list view to a gallery view.

The comment tag associated with creating categorized views is ANDROID_CUSTOMIZATION_POINT_HYBRIDAPPLIST.

  1. Add an XML layout called hybridappgallery.xml to the HybridWebContainer project.
  2. Match your hybridappgallery.xml layout to:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        
        <Gallery xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/gallery"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    
    </LinearLayout>
    
  3. Create a new activity for the HybridWebContainer.
    1. Open the AndroidManifest.xml file.
    2. Click the Application tab.
    3. In the Application Nodes section (at the bottom left), click Add.
    4. Choose Activity and click OK.
    5. Select the new activity and change its name to com.sybase.hwc.HybridAppGalleryActivity.
    6. Click Name* to generate the stub Java file.
    7. Click Finish.
  4. Enter this code into the HybridAppGalleryActivity.java file:
    package com.sybase.hwc;
    
    import java.util.ArrayList;
    import java.util.Vector;
    import java.util.Arrays;
    
    import com.sybase.hybridApp.*;
    import com.sybase.hybridApp.amp.Consts;
    
    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.BaseAdapter;
    import android.widget.Gallery;
    import android.widget.ImageView;
    
    public class HybridAppGalleryActivity extends Activity {
       
       ImageAdapter m_adapter;
    
       /** Called when the activity is first created. */
       @Override
       public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
       
           setContentView(R.layout.hybridappgallery);
           
           Gallery oGallery = (Gallery) findViewById(R.id.gallery);
           m_adapter = new ImageAdapter(this);
           oGallery.setAdapter(m_adapter);
           
           oGallery.setOnItemClickListener(new OnItemClickListener ()
           {
              public void onItemClick(AdapterView parent, View v, int position, long id)
              {
                 startHybridApp(parent, v, position, id);
              }
           });
       }
       
       
        public void startHybridApp(AdapterView  oParent, View  v, int iPos, long id )
        {
            Intent oIntentHybridAppContainer =  new Intent( this, UiHybridAppContainer.class );
            oIntentHybridAppContainer.putExtra( Consts.INTENT_PARAM_WORKFLOW_START_MODE, Consts.START_MODE_WORKFLOW );
            oIntentHybridAppContainer.putExtra( Consts.INTENT_PARAM_WORKFLOW_ID, m_adapter.getItem( iPos ).getHybridAppId() );
            oIntentHybridAppContainer.putExtra( Consts.INTENT_PARAM_WORKFLOW_PROGRESS_TEXT, m_adapter.getItem( iPos ).getDisplayName() );
            startActivityForResult( oIntentHybridAppContainer, Consts.INTENT_ID_WORKFLOW_CONTAINER );
        }
       
       @Override
       public void onActivityResult( int iRequestCode, int iResultCode, Intent relaunchData )
       {
          super.onActivityResult( iRequestCode, iResultCode, relaunchData );
          if ( iRequestCode == Consts.INTENT_ID_WORKFLOW_CONTAINER && iResultCode == Consts.RESULT_RELAUNCH )
          {
                Intent oIntentHybridAppContainer =  new Intent( this, UiHybridAppContainer.class );
                oIntentHybridAppContainer.putExtra( Consts.INTENT_PARAM_WORKFLOW_START_MODE, Consts.START_MODE_WORKFLOW );
                oIntentHybridAppContainer.putExtra( Consts.INTENT_PARAM_WORKFLOW_ID, relaunchData.getIntExtra( Consts.INTENT_PARAM_WORKFLOW_ID, 0 ));
                oIntentHybridAppContainer.putExtra( Consts.INTENT_PARAM_WORKFLOW_PROGRESS_TEXT, relaunchData.getStringExtra( Consts.INTENT_PARAM_WORKFLOW_PROGRESS_TEXT ));
                startActivityForResult( oIntentHybridAppContainer, Consts.INTENT_ID_WORKFLOW_CONTAINER );
          }
       }
       
       public class ImageAdapter extends BaseAdapter
       {
          //int mGalleryItemBackground;
          private Context mContext;
          private Vector<HybridApp> mHybridApps;
          
          private ArrayList<Integer> mImageIds;
          
          public ImageAdapter(Context c)
          {
             mContext = c;
             mImageIds = new ArrayList<Integer>();
             
             //have to get a list of all installed HybridAppss
             mHybridApps = new Vector<HybridApp>( Arrays.asList(HybridAppDb.getInvocableHybridApps()) );
             for(int iHybridAppIndex = 0; iHybridAppIndex < mHybridApps.size(); iHybridAppIndex++)
             {
                HybridAppDb oHybridApp = (HybridAppDb) mHybridApps.get(iHybridAppIndex);
                int iconIndex = oHybridApp.getIconIndex();
                if(iconIndex >= 30 &&
                   iconIndex <= 116)
                {
                   //luckily the icon resources are consecutive
                   int iResource = 0;
                   if(iconIndex < 100)
                   {
                      iResource = 0x7f020022;
                      iResource += (iconIndex - 30)*2;
                   }
                   else
                   {
                      iResource = 0x7f020000;
                      iResource += (iconIndex - 100)*2;
                   }
                   mImageIds.add(new Integer(iResource));
                }
             }
          }
          
          public int getHybridAppId(int position)
          {
             return ((HybridAppDb)mHybridApps.get(position)).getHybridAppId();
          }
          
          public String getDisplayName(int position)
          {
             return ((HybridAppDb)mHybridApps.get(position)).getDisplayName();
          }
          
          public int getCount()
          {
             return mImageIds.size();
          }
          
          public HybridAppDb getItem(int position)
          {
             return (HybridAppDb)mHybridApps.get(position);
          }
          
          public long getItemId(int position)
          {
             return position;
          }
          
          public View getView(int position, View convertView, ViewGroup parent)
          {
             ImageView imageView = new ImageView(mContext);
             
             imageView.setImageResource(mImageIds.get(position).intValue());
             imageView.setLayoutParams(new Gallery.LayoutParams(150,100));
             imageView.setScaleType(ImageView.ScaleType.FIT_XY);
             
             return imageView;
          }
       }
    
    }
    
  5. Save the file.
  6. 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.
    That class must extend Activity.
  7. Update the manifest.xml file to include the new activity you create.