public static ActionBarSherlock wrap(Activity activity, int flags) {
        //Create a local implementation map we can modify
        HashMap<Implementation, Class<? extends ActionBarSherlock>> impls =
                new HashMap<Implementation, Class<? extends ActionBarSherlock>>(IMPLEMENTATIONS);
        boolean hasQualfier;

        /* DPI FILTERING */
        hasQualfier = false;
        for (Implementation key : impls.keySet()) {
            //Only honor TVDPI as a specific qualifier
            if (key.dpi() == DisplayMetrics.DENSITY_TV) {
                hasQualfier = true;
                break;
            }
        }
        if (hasQualfier) {
            final boolean isTvDpi = activity.getResources().getDisplayMetrics().densityDpi == DisplayMetrics.DENSITY_TV;
            for (Iterator<Implementation> keys = impls.keySet().iterator(); keys.hasNext(); ) {
                int keyDpi = keys.next().dpi();
                if ((isTvDpi && keyDpi != DisplayMetrics.DENSITY_TV)
                        || (!isTvDpi && keyDpi == DisplayMetrics.DENSITY_TV)) {
                    keys.remove();
                }
            }
        }

        /* API FILTERING */
        hasQualfier = false;
        for (Implementation key : impls.keySet()) {
            if (key.api() != Implementation.DEFAULT_API) {
                hasQualfier = true;
                break;
            }
        }
        if (hasQualfier) {
            final int runtimeApi = Build.VERSION.SDK_INT;
            int bestApi = 0;
            for (Iterator<Implementation> keys = impls.keySet().iterator(); keys.hasNext(); ) {
                int keyApi = keys.next().api();
                if (keyApi > runtimeApi) {
                    keys.remove();
                } else if (keyApi > bestApi) {
                    bestApi = keyApi;
                }
            }
            for (Iterator<Implementation> keys = impls.keySet().iterator(); keys.hasNext(); ) {
                if (keys.next().api() != bestApi) {
                    keys.remove();
                }
            }
        }

        if (impls.size() > 1) {
            throw new IllegalStateException("More than one implementation matches configuration.");
        }
        if (impls.isEmpty()) {
            throw new IllegalStateException("No implementations match configuration.");
        }
        Class<? extends ActionBarSherlock> impl = impls.values().iterator().next();
        if (DEBUG) Log.i(TAG, "Using implementation: " + impl.getSimpleName());

        try {
            Constructor<? extends ActionBarSherlock> ctor = impl.getConstructor(CONSTRUCTOR_ARGS);
            return ctor.newInstance(activity, flags);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
public static ActionBarSherlock wrap ( Activity activity , int flags ) { HashMap < Implementation , Class < ? extends ActionBarSherlock > > impls = new HashMap < Implementation , Class < ? extends ActionBarSherlock > > ( IMPLEMENTATIONS ) ; boolean hasQualfier ; hasQualfier = false ; for ( Implementation key : impls . keySet ( ) ) { if ( key . dpi ( ) == DisplayMetrics . DENSITY_TV ) { hasQualfier = true ; break ; } } if ( hasQualfier ) { final boolean isTvDpi = activity . getResources ( ) . getDisplayMetrics ( ) . densityDpi == DisplayMetrics . DENSITY_TV ; for ( Iterator < Implementation > keys = impls . keySet ( ) . iterator ( ) ; keys . hasNext ( ) ; ) { int keyDpi = keys . next ( ) . dpi ( ) ; if ( ( isTvDpi && keyDpi != DisplayMetrics . DENSITY_TV ) || ( ! isTvDpi && keyDpi == DisplayMetrics . DENSITY_TV ) ) { keys . remove ( ) ; } } } hasQualfier = false ; for ( Implementation key : impls . keySet ( ) ) { if ( key . api ( ) != Implementation . DEFAULT_API ) { hasQualfier = true ; break ; } } if ( hasQualfier ) { final int runtimeApi = Build . VERSION . SDK_INT ; int bestApi = 0 ; for ( Iterator < Implementation > keys = impls . keySet ( ) . iterator ( ) ; keys . hasNext ( ) ; ) { int keyApi = keys . next ( ) . api ( ) ; if ( keyApi > runtimeApi ) { keys . remove ( ) ; } else if ( keyApi > bestApi ) { bestApi = keyApi ; } } for ( Iterator < Implementation > keys = impls . keySet ( ) . iterator ( ) ; keys . hasNext ( ) ; ) { if ( keys . next ( ) . api ( ) != bestApi ) { keys . remove ( ) ; } } } if ( impls . size ( ) > 1 ) { throw new IllegalStateException ( "More than one implementation matches configuration." ) ; } if ( impls . isEmpty ( ) ) { throw new IllegalStateException ( "No implementations match configuration." ) ; } Class < ? extends ActionBarSherlock > impl = impls . values ( ) . iterator ( ) . next ( ) ; if ( DEBUG ) Log . i ( TAG , "Using implementation: " + impl . getSimpleName ( ) ) ; try { Constructor < ? extends ActionBarSherlock > ctor = impl . getConstructor ( CONSTRUCTOR_ARGS ) ; return ctor . newInstance ( activity , flags ) ; } catch ( NoSuchMethodException e ) { throw new RuntimeException ( e ) ; } catch ( IllegalArgumentException e ) { throw new RuntimeException ( e ) ; } catch ( InstantiationException e ) { throw new RuntimeException ( e ) ; } catch ( IllegalAccessException e ) { throw new RuntimeException ( e ) ; } catch ( InvocationTargetException e ) { throw new RuntimeException ( e ) ; } }
Wrap an activity with an action bar abstraction which will enable the
use of a custom implementation on platforms where a native version does
not exist.

@param activity Owning activity.
@param flags Option flags to control behavior.
@return Instance to interact with the action bar.