Replay - Performance Techniques

As mentioned in the Performance article, image capture must happen on the UI thread, which can have a noticeable effect on the UI in some cases if not handled properly. ForeSee takes care not to perform image captures when UI responsiveness is critical, e.g., during scrolling. There are some cases that cannot be handled automatically, however, so the SDK provides ways for the client to mitigate the performance impact.

Fragments

Although the SDK registers most layout changes within the app automatically, fragments pose a particular problem since they do not adhere to the same rules as the rest of the view hierarchy. To prevent possible performance issues when using fragments, the client should be sure to register new fragments with the SDK by calling ForeSee.registerFragmentView(yourFragmentView); in the fragment’s onCreateView() method. For example, a typical onCreateView() method might look like the following:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_holidays, container, false);

    // The client's code
        
    // Register the new view for this fragment
    ForeSee.registerFragmentView(rootView);
    return rootView;
}

The SDK provides a custom implementation of android.widget.Gallery that prevents image capture from taking place while the Gallery is scrolling. This allows the Gallery to animate smoothly with no impact to the responsiveness of the app.

Note
This is only necessary in versions of Android below 4.0. In all versions above,
the SDK can automatically detect scrolling of Galleries.

To use ForeSee’s custom Gallery implementation, clients can update their layout like so:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <com.foresee.sdk.instrumentation.ForeSeeGallery
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/gallery">
    <!-- The contents of the client's gallery-->
    </com.foresee.sdk.instrumentation.ForeSeeGallery>
</LinearLayout>

Custom View Subclasses

If the client has a custom View subclass, it is recommended that they notify the SDK when the UI is busy, usually during a layout or a draw. This ensures the image capture process has as little impact as possible on the rendering performance of the custom View.

The basic guideline is to call ForeSee.registerInterfaceActivity() whenever the client’s custom View subclass updates the UI, either by laying out its subviews or drawing directly to the Canvas.

Calling ForeSee.registerInterfaceActivity() notifies the SDK to skip the currently queued image capture which has the effect of not disrupting the UI thread while the view needs to render.

Example

public class MyCustomView extends View {
    protected void onLayout(boolean changed, int left, int top, int right,_
        int bottom)
        {
        // Calling registerInterfaceActivity BEFORE the layout code ensures
        // there won't be an image capture while the View does a layout.
        ForeSee.registerInterfaceActivity();

        // The client's normal layout code
    }
}

Another best practice is to notify the SDK as early as possible about any impending UI updates. For example, if the client’s custom view responds to a fling gesture, it is recommended to call registerInterfaceActivty() in the onFling implementation as well as in the View’s onLayout/onDraw.

Example

public class AnotherCustomView extends View implements GestureDetector._
    OnGestureListener
    {
    public boolean onFling(MotionEvent event1, MotionEvent event2,
            float velocityX, float velocityY) {
        ForeSee.registerInterfaceActivity();

        // Additional processing
        return true;
    }

    protected void onLayout(boolean changed, int left, int top, int right,_
        int bottom)
    {
        ForeSee.registerInterfaceActivity();

        // The client's normal layout code
    }
}

Other articles in this section:

  1. Replay Overview
  2. Sessions
  3. Paging
  4. Masking
  5. Performance
  6. Limitations
  7. Custom Touch Capture
  8. Custom Image Capture
  9. Performance Techniques (current article)
  10. Remote Disable