Making the List of Mobile Workflow Packages Searchable

Make the list of Mobile Workflow packages searchable.

The comment tag associated with making the list of Workflow packages searchable is ANDROID_CUSTOMIZATION_POINT_HYBRIDAPPSEARCH.

  1. Add an XML layout called emptyview.xml, and do not add anything to the resulting autogenerated XML file.
  2. Open the workflows_list.xml file for editing and add the following tag above the ListView tag:
    <EditText
        android:hint="@string/SEARCH_HINT"
        android:id="@+id/EditTextSearchHybridAppList"
        android:layout_width="match_parent"
        android:layout_height="47dp" />
    
  3. Open ...\Values\Strings.xml and, between the <resource> and </resource> tags, add:
       <string name="SEARCH_HINT">search</string>
  4. Copy the UiHybridAppScreen.java file to your own class name, for example, SearchableAppScreen.java and open it for editing.
    1. Add these import statements:
      import android.widget.EditText; 
      import android.text.Editable;
      import android.text.TextWatcher;
      
      
    2. Add the following code to the end of the onCreate method:
      final EditText edittext = (EditText) findViewById(R.id.EditTextSearchHybridAppList);
      edittext.addTextChangedListener( new TextWatcher()
      {
         public void afterTextChanged( Editable s)
         {
            String sSearchFor = s.toString();
            m_adapter.setSearch( sSearchFor );
            m_adapter.notifyDataSetChanged();
         }
                 
         // stubs; have to implement the abstract methods
         public void beforeTextChanged( CharSequence s, int start, int count, int after ) {}
         public void onTextChanged( CharSequence s, int start, int before, int count) {}
      });
      
    3. Add this member variable to the HybridAppAdapter class:
      String m_sToSearchFor;
    4. Add this line of code to the end of the HybridAppAdapter contstructor method:
      m_sToSearchFor = ""; 
    5. Replace the code inside the getView method with:
      public View getView(int position, View convertView, ViewGroup parent)
      {
         LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         View v = vi.inflate(R.layout.workflows, null);
          
         HybridApp oHybridApp = getItem( position );
         if( oHybridApp != null )
         {
            if( m_abDisplayThisApp == null || position >= m_abDisplayThisApp.length || m_abDisplayThisApp[position]) 
            {
               ImageView ic = (ImageView) v.findViewById( R.id.workflow_icon );
               ic.setImageResource( UiIconIndexLookup.getNormalIconIdForIndex( oHybridApp.getIconIndex() ));
               TextView tt = (TextView) v.findViewById(R.id.workflow_title);
               if (tt != null)
               {
                  tt.setText( oHybridApp.getDisplayName());
               }
            }
            else
            {
              v = vi.inflate(R.layout.emptyview, null);
            }
          }
         return v;
      }
      
      
    6. Add a search method to the HybridAppAdapter class:
      public void search()
      {
         m_abDisplayThisApp = new boolean[m_adapter.getCount()];
      	                    
         for(int index = 0; index < m_adapter.getCount(); index++)
         {
            int iIndexOfResult = m_adapter.getItem( index ).getDisplayName().indexOf( m_sToSearchFor );
            if( iIndexOfResult >= 0 )
            {
               m_abDisplayThisApp[index] = true;
            }
         }
      }
      
    7. Add these methods to the HybridAppAdapter class:
      public void notifyDataSetChanged()
      {
        search();
        super.notifyDataSetChanged();
      }
      public void setSearch( String sSearchFor )
      {
         m_sToSearchFor = sSearchFor;
       }
      
    8. Add this member variable to the UiHybridAppScreen class:
      private boolean[] m_abDisplayThisApp;
  5. 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.
  6. Open the file you created in step 4, 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.
  7. Update the manifest.xml file to include the new activity you create.