Search in sources :

Example 86 with BridgeContext

use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.

the class RenderSessionImpl method insertChild.

/**
     * Insert a new child into an existing parent.
     * <p>
     * {@link #acquire(long)} must have been called before this.
     *
     * @throws IllegalStateException if the current context is different than the one owned by
     *      the scene, or if {@link #acquire(long)} was not called.
     *
     * @see RenderSession#insertChild(Object, ILayoutPullParser, int, IAnimationListener)
     */
public Result insertChild(final ViewGroup parentView, ILayoutPullParser childXml, final int index, IAnimationListener listener) {
    checkLock();
    BridgeContext context = getContext();
    // create a block parser for the XML
    BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(childXml, context, false);
    // inflate the child without adding it to the root since we want to control where it'll
    // get added. We do pass the parentView however to ensure that the layoutParams will
    // be created correctly.
    final View child = mInflater.inflate(blockParser, parentView, false);
    blockParser.ensurePopped();
    invalidateRenderingSize();
    if (listener != null) {
        new AnimationThread(this, "insertChild", listener) {

            @Override
            public Result preAnimation() {
                parentView.setLayoutTransition(new LayoutTransition());
                return addView(parentView, child, index);
            }

            @Override
            public void postAnimation() {
                parentView.setLayoutTransition(null);
            }
        }.start();
        // always return success since the real status will come through the listener.
        return SUCCESS.createResult(child);
    }
    // add it to the parentView in the correct location
    Result result = addView(parentView, child, index);
    if (!result.isSuccess()) {
        return result;
    }
    result = render(false);
    if (result.isSuccess()) {
        result = result.getCopyWithData(child);
    }
    return result;
}
Also used : AnimationThread(android.animation.AnimationThread) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) LayoutTransition(android.animation.LayoutTransition) MenuView(com.android.internal.view.menu.MenuView) View(android.view.View) AdapterView(android.widget.AdapterView) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView) IconMenuItemView(com.android.internal.view.menu.IconMenuItemView) ListView(android.widget.ListView) ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) AbsListView(android.widget.AbsListView) ActionMenuView(android.widget.ActionMenuView) ExpandableListView(android.widget.ExpandableListView) BridgeXmlBlockParser(com.android.layoutlib.bridge.android.BridgeXmlBlockParser) Result(com.android.ide.common.rendering.api.Result)

Example 87 with BridgeContext

use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.

the class RenderSessionImpl method getViewKey.

/* (non-Javadoc)
     * The cookie for menu items are stored in menu item and not in the map from View stored in
     * BridgeContext.
     */
@Nullable
private Object getViewKey(View view) {
    BridgeContext context = getContext();
    if (!(view instanceof MenuView.ItemView)) {
        return context.getViewKey(view);
    }
    MenuItemImpl menuItem;
    if (view instanceof ActionMenuItemView) {
        menuItem = ((ActionMenuItemView) view).getItemData();
    } else if (view instanceof ListMenuItemView) {
        menuItem = ((ListMenuItemView) view).getItemData();
    } else if (view instanceof IconMenuItemView) {
        menuItem = ((IconMenuItemView) view).getItemData();
    } else {
        menuItem = null;
    }
    if (menuItem instanceof BridgeMenuItemImpl) {
        return ((BridgeMenuItemImpl) menuItem).getViewCookie();
    }
    return null;
}
Also used : BridgeMenuItemImpl(com.android.internal.view.menu.BridgeMenuItemImpl) MenuItemImpl(com.android.internal.view.menu.MenuItemImpl) BridgeMenuItemImpl(com.android.internal.view.menu.BridgeMenuItemImpl) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView) IconMenuItemView(com.android.internal.view.menu.IconMenuItemView) ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) IconMenuItemView(com.android.internal.view.menu.IconMenuItemView) ListMenuItemView(com.android.internal.view.menu.ListMenuItemView) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) ActionMenuItemView(com.android.internal.view.menu.ActionMenuItemView) Nullable(android.annotation.Nullable)

Example 88 with BridgeContext

use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.

the class HandlerThread_Delegate method run.

// -------- Delegate methods
@LayoutlibDelegate
static /*package*/
void run(HandlerThread theThread) {
    // record the thread so that it can be quit() on clean up.
    BridgeContext context = RenderAction.getCurrentContext();
    List<HandlerThread> list = sThreads.get(context);
    if (list == null) {
        list = new ArrayList<HandlerThread>();
        sThreads.put(context, list);
    }
    list.add(theThread);
    // ---- START DEFAULT IMPLEMENTATION.
    theThread.mTid = Process.myTid();
    Looper.prepare();
    synchronized (theThread) {
        theThread.mLooper = Looper.myLooper();
        theThread.notifyAll();
    }
    Process.setThreadPriority(theThread.mPriority);
    theThread.onLooperPrepared();
    Looper.loop();
    theThread.mTid = -1;
}
Also used : BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 89 with BridgeContext

use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.

the class Main method testGetResourceNameVariants.

@Test
public void testGetResourceNameVariants() throws Exception {
    // Setup
    SessionParams params = createSessionParams("", ConfigGenerator.NEXUS_4);
    AssetManager assetManager = AssetManager.getSystem();
    DisplayMetrics metrics = new DisplayMetrics();
    Configuration configuration = RenderAction.getConfiguration(params);
    Resources resources = new Resources(assetManager, metrics, configuration);
    resources.mLayoutlibCallback = params.getLayoutlibCallback();
    resources.mContext = new BridgeContext(params.getProjectKey(), metrics, params.getResources(), params.getAssets(), params.getLayoutlibCallback(), configuration, params.getTargetSdkVersion(), params.isRtlSupported());
    // Test
    assertEquals("android:style/ButtonBar", resources.getResourceName(android.R.style.ButtonBar));
    assertEquals("android", resources.getResourcePackageName(android.R.style.ButtonBar));
    assertEquals("ButtonBar", resources.getResourceEntryName(android.R.style.ButtonBar));
    assertEquals("style", resources.getResourceTypeName(android.R.style.ButtonBar));
    int id = resources.mLayoutlibCallback.getResourceId(ResourceType.STRING, "app_name");
    assertEquals("com.android.layoutlib.test.myapplication:string/app_name", resources.getResourceName(id));
    assertEquals("com.android.layoutlib.test.myapplication", resources.getResourcePackageName(id));
    assertEquals("string", resources.getResourceTypeName(id));
    assertEquals("app_name", resources.getResourceEntryName(id));
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) AssetManager(android.content.res.AssetManager) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(android.content.res.Configuration) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) FrameworkResources(com.android.ide.common.resources.FrameworkResources) Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics) Test(org.junit.Test)

Example 90 with BridgeContext

use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.

the class BridgeInflater method inflate.

@Override
public View inflate(int resource, ViewGroup root) {
    Context context = getContext();
    context = getBaseContext(context);
    if (context instanceof BridgeContext) {
        BridgeContext bridgeContext = (BridgeContext) context;
        ResourceValue value = null;
        @SuppressWarnings("deprecation") Pair<ResourceType, String> layoutInfo = Bridge.resolveResourceId(resource);
        if (layoutInfo != null) {
            value = bridgeContext.getRenderResources().getFrameworkResource(ResourceType.LAYOUT, layoutInfo.getSecond());
        } else {
            layoutInfo = mLayoutlibCallback.resolveResourceId(resource);
            if (layoutInfo != null) {
                value = bridgeContext.getRenderResources().getProjectResource(ResourceType.LAYOUT, layoutInfo.getSecond());
            }
        }
        if (value != null) {
            File f = new File(value.getValue());
            if (f.isFile()) {
                try {
                    XmlPullParser parser = ParserFactory.create(f, true);
                    BridgeXmlBlockParser bridgeParser = new BridgeXmlBlockParser(parser, bridgeContext, value.isFramework());
                    return inflate(bridgeParser, root);
                } catch (Exception e) {
                    Bridge.getLog().error(LayoutLog.TAG_RESOURCES_READ, "Failed to parse file " + f.getAbsolutePath(), e, null);
                    return null;
                }
            }
        }
    }
    return null;
}
Also used : Context(android.content.Context) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) BridgeContext.getBaseContext(com.android.layoutlib.bridge.android.BridgeContext.getBaseContext) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) XmlPullParser(org.xmlpull.v1.XmlPullParser) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) ResourceType(com.android.resources.ResourceType) File(java.io.File) BridgeXmlBlockParser(com.android.layoutlib.bridge.android.BridgeXmlBlockParser)

Aggregations

BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)112 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)40 Context (android.content.Context)31 View (android.view.View)24 AdapterView (android.widget.AdapterView)24 RenderResources (com.android.ide.common.rendering.api.RenderResources)24 BridgeXmlBlockParser (com.android.layoutlib.bridge.android.BridgeXmlBlockParser)24 SessionParams (com.android.ide.common.rendering.api.SessionParams)23 ActionMenuItemView (com.android.internal.view.menu.ActionMenuItemView)20 IconMenuItemView (com.android.internal.view.menu.IconMenuItemView)20 ListMenuItemView (com.android.internal.view.menu.ListMenuItemView)20 AbsListView (android.widget.AbsListView)18 ExpandableListView (android.widget.ExpandableListView)18 ListView (android.widget.ListView)18 Result (com.android.ide.common.rendering.api.Result)18 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)17 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)16 ActionMenuView (android.widget.ActionMenuView)15 MenuView (com.android.internal.view.menu.MenuView)15 Drawable (android.graphics.drawable.Drawable)13