FileDocCategorySizeDatePackage
AppCompatActionBar.javaAPI DocAndroid 5.1 API6412Thu Mar 12 22:22:44 GMT 2015com.android.layoutlib.bridge.bars

AppCompatActionBar

public class AppCompatActionBar extends BridgeActionBar
Assumes that the AppCompat library is present in the project's classpath and creates an actionbar around it.

Fields Summary
private Object
mWindowDecorActionBar
private static final String
WINDOW_ACTION_BAR_CLASS
private Class
mWindowActionBarClass
Constructors Summary
public AppCompatActionBar(com.android.layoutlib.bridge.android.BridgeContext context, com.android.ide.common.rendering.api.SessionParams params, android.view.ViewGroup parentView)
Inflate the action bar and attach it to {@code parentView}


                   
          
               
        super(context, params, parentView);
        int contentRootId = context.getProjectResourceValue(ResourceType.ID,
                "action_bar_activity_content", 0);
        View contentView = getDecorContent().findViewById(contentRootId);
        if (contentView != null) {
            assert contentView instanceof FrameLayout;
            setContentRoot(((FrameLayout) contentView));
        } else {
            // Something went wrong. Create a new FrameLayout in the enclosing layout.
            FrameLayout contentRoot = new FrameLayout(context);
            setMatchParent(contentRoot);
            mEnclosingLayout.addView(contentRoot);
            setContentRoot(contentRoot);
        }
        try {
            Class[] constructorParams = {View.class};
            Object[] constructorArgs = {getDecorContent()};
            mWindowDecorActionBar = params.getProjectCallback().loadView(WINDOW_ACTION_BAR_CLASS,
                    constructorParams, constructorArgs);

            mWindowActionBarClass = mWindowDecorActionBar == null ? null :
                    mWindowDecorActionBar.getClass();
            setupActionBar();
        } catch (Exception e) {
            e.printStackTrace();
        }
    
Methods Summary
public voidcreateMenuPopup()

        // it's hard to addd menus to appcompat's actionbar, since it'll use a lot of reflection.
        // so we skip it for now.
    
private android.graphics.drawable.DrawablegetDrawable(java.lang.String name, boolean isFramework)

        RenderResources res = mBridgeContext.getRenderResources();
        ResourceValue value = res.findResValue(name, isFramework);
        value = res.resolveResValue(value);
        if (value != null) {
            return ResourceHelper.getDrawable(value, mBridgeContext);
        }
        return null;
    
protected com.android.ide.common.rendering.api.ResourceValuegetLayoutResource(com.android.layoutlib.bridge.android.BridgeContext context)

        // We always assume that the app has requested the action bar.
        return context.getRenderResources().getProjectResource(ResourceType.LAYOUT,
                "abc_screen_toolbar");
    
private static java.lang.reflect.MethodgetMethod(java.lang.Class owner, java.lang.String name, java.lang.Class parameterTypes)

        try {
            return owner == null ? null : owner.getMethod(name, parameterTypes);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        return null;
    
private static java.lang.Objectinvoke(java.lang.reflect.Method method, java.lang.Object owner, java.lang.Object args)

        try {
            return method == null ? null : method.invoke(owner, args);
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    
protected voidsetHomeAsUp(boolean homeAsUp)

        if (mWindowDecorActionBar != null) {
            Method setHomeAsUp = getMethod(mWindowActionBarClass,
                    "setDefaultDisplayHomeAsUpEnabled", boolean.class);
            invoke(setHomeAsUp, mWindowDecorActionBar, homeAsUp);
        }
    
protected voidsetIcon(java.lang.String icon)

        // Do this only if the action bar doesn't already have an icon.
        if (icon != null && !icon.isEmpty() && mWindowDecorActionBar != null) {
            if (((Boolean) invoke(getMethod(mWindowActionBarClass, "hasIcon"), mWindowDecorActionBar)
            )) {
                Drawable iconDrawable = getDrawable(icon, false);
                if (iconDrawable != null) {
                    Method setIcon = getMethod(mWindowActionBarClass, "setIcon", Drawable.class);
                    invoke(setIcon, mWindowDecorActionBar, iconDrawable);
                }
            }
        }
    
protected voidsetSubtitle(java.lang.CharSequence subtitle)

        if (subtitle != null && mWindowDecorActionBar != null) {
            Method setSubtitle = getMethod(mWindowActionBarClass, "setSubtitle", CharSequence.class);
            invoke(setSubtitle, mWindowDecorActionBar, subtitle);
        }
    
protected voidsetTitle(java.lang.CharSequence title)

        if (title != null && mWindowDecorActionBar != null) {
            Method setTitle = getMethod(mWindowActionBarClass, "setTitle", CharSequence.class);
            invoke(setTitle, mWindowDecorActionBar, title);
        }