Search in sources :

Example 16 with ResourceReference

use of com.android.ide.common.rendering.api.ResourceReference in project android_frameworks_base by ParanoidAndroid.

the class FakeExpandableAdapter method createItems.

private void createItems(Iterable<DataBindingItem> iterable, final int itemCount, final int repeatCount, List<ResourceReference> types, int depth) {
    // Need an array to count for each type.
    // This is likely too big, but is the max it can be.
    int[] typeCount = new int[itemCount];
    // we put several repeating sets.
    for (int r = 0; r < repeatCount; r++) {
        // loop on the type of list items, and add however many for each type.
        for (DataBindingItem dataBindingItem : iterable) {
            ResourceReference viewRef = dataBindingItem.getViewReference();
            int typeIndex = types.indexOf(viewRef);
            if (typeIndex == -1) {
                typeIndex = types.size();
                types.add(viewRef);
            }
            List<DataBindingItem> children = dataBindingItem.getChildren();
            int count = dataBindingItem.getCount();
            // if there are children, we use the count as a repeat count for the children.
            if (children.size() > 0) {
                count = 1;
            }
            int index = typeCount[typeIndex];
            typeCount[typeIndex] += count;
            for (int k = 0; k < count; k++) {
                AdapterItem item = new AdapterItem(dataBindingItem, typeIndex, mItems.size(), index++);
                mItems.add(item);
                if (children.size() > 0) {
                    createItems(dataBindingItem, depth + 1);
                }
            }
        }
    }
}
Also used : DataBindingItem(com.android.ide.common.rendering.api.DataBindingItem) ResourceReference(com.android.ide.common.rendering.api.ResourceReference)

Example 17 with ResourceReference

use of com.android.ide.common.rendering.api.ResourceReference in project android_frameworks_base by DirtyUnicorns.

the class Resources_Theme_Delegate method resolveStyle.

@Nullable
private static StyleResourceValue resolveStyle(int nativeResid) {
    if (nativeResid == 0) {
        return null;
    }
    BridgeContext context = RenderSessionImpl.getCurrentContext();
    ResourceReference theme = context.resolveId(nativeResid);
    if (theme.isFramework()) {
        return (StyleResourceValue) context.getRenderResources().getFrameworkResource(ResourceType.STYLE, theme.getName());
    } else {
        return (StyleResourceValue) context.getRenderResources().getProjectResource(ResourceType.STYLE, theme.getName());
    }
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) ResourceReference(com.android.ide.common.rendering.api.ResourceReference) Nullable(android.annotation.Nullable)

Example 18 with ResourceReference

use of com.android.ide.common.rendering.api.ResourceReference in project android_frameworks_base by DirtyUnicorns.

the class RenderSessionImpl method postInflateProcess.

/**
     * Post process on a view hierarchy that was just inflated.
     * <p/>
     * At the moment this only supports TabHost: If {@link TabHost} is detected, look for the
     * {@link TabWidget}, and the corresponding {@link FrameLayout} and make new tabs automatically
     * based on the content of the {@link FrameLayout}.
     * @param view the root view to process.
     * @param layoutlibCallback callback to the project.
     * @param skip the view and it's children are not processed.
     */
// For the use of Pair
@SuppressWarnings("deprecation")
private void postInflateProcess(View view, LayoutlibCallback layoutlibCallback, View skip) throws PostInflateException {
    if (view == skip) {
        return;
    }
    if (view instanceof TabHost) {
        setupTabHost((TabHost) view, layoutlibCallback);
    } else if (view instanceof QuickContactBadge) {
        QuickContactBadge badge = (QuickContactBadge) view;
        badge.setImageToDefault();
    } else if (view instanceof AdapterView<?>) {
        // get the view ID.
        int id = view.getId();
        BridgeContext context = getContext();
        // get a ResourceReference from the integer ID.
        ResourceReference listRef = context.resolveId(id);
        if (listRef != null) {
            SessionParams params = getParams();
            AdapterBinding binding = params.getAdapterBindings().get(listRef);
            // if there was no adapter binding, trying to get it from the call back.
            if (binding == null) {
                binding = layoutlibCallback.getAdapterBinding(listRef, context.getViewKey(view), view);
            }
            if (binding != null) {
                if (view instanceof AbsListView) {
                    if ((binding.getFooterCount() > 0 || binding.getHeaderCount() > 0) && view instanceof ListView) {
                        ListView list = (ListView) view;
                        boolean skipCallbackParser = false;
                        int count = binding.getHeaderCount();
                        for (int i = 0; i < count; i++) {
                            Pair<View, Boolean> pair = context.inflateView(binding.getHeaderAt(i), list, false, skipCallbackParser);
                            if (pair.getFirst() != null) {
                                list.addHeaderView(pair.getFirst());
                            }
                            skipCallbackParser |= pair.getSecond();
                        }
                        count = binding.getFooterCount();
                        for (int i = 0; i < count; i++) {
                            Pair<View, Boolean> pair = context.inflateView(binding.getFooterAt(i), list, false, skipCallbackParser);
                            if (pair.getFirst() != null) {
                                list.addFooterView(pair.getFirst());
                            }
                            skipCallbackParser |= pair.getSecond();
                        }
                    }
                    if (view instanceof ExpandableListView) {
                        ((ExpandableListView) view).setAdapter(new FakeExpandableAdapter(listRef, binding, layoutlibCallback));
                    } else {
                        ((AbsListView) view).setAdapter(new FakeAdapter(listRef, binding, layoutlibCallback));
                    }
                } else if (view instanceof AbsSpinner) {
                    ((AbsSpinner) view).setAdapter(new FakeAdapter(listRef, binding, layoutlibCallback));
                }
            }
        }
    } else if (view instanceof ViewGroup) {
        mInflater.postInflateProcess(view);
        ViewGroup group = (ViewGroup) view;
        final int count = group.getChildCount();
        for (int c = 0; c < count; c++) {
            View child = group.getChildAt(c);
            postInflateProcess(child, layoutlibCallback, skip);
        }
    }
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) TabHost(android.widget.TabHost) ViewGroup(android.view.ViewGroup) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) AbsListView(android.widget.AbsListView) FakeAdapter(com.android.layoutlib.bridge.impl.binding.FakeAdapter) FakeExpandableAdapter(com.android.layoutlib.bridge.impl.binding.FakeExpandableAdapter) 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) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) ExpandableListView(android.widget.ExpandableListView) QuickContactBadge(android.widget.QuickContactBadge) AdapterBinding(com.android.ide.common.rendering.api.AdapterBinding) AbsSpinner(android.widget.AbsSpinner) AdapterView(android.widget.AdapterView) ResourceReference(com.android.ide.common.rendering.api.ResourceReference) ExpandableListView(android.widget.ExpandableListView)

Example 19 with ResourceReference

use of com.android.ide.common.rendering.api.ResourceReference in project android_frameworks_base by DirtyUnicorns.

the class FakeExpandableAdapter method createItems.

private void createItems(Iterable<DataBindingItem> iterable, final int itemCount, final int repeatCount, List<ResourceReference> types, int depth) {
    // Need an array to count for each type.
    // This is likely too big, but is the max it can be.
    int[] typeCount = new int[itemCount];
    // we put several repeating sets.
    for (int r = 0; r < repeatCount; r++) {
        // loop on the type of list items, and add however many for each type.
        for (DataBindingItem dataBindingItem : iterable) {
            ResourceReference viewRef = dataBindingItem.getViewReference();
            int typeIndex = types.indexOf(viewRef);
            if (typeIndex == -1) {
                typeIndex = types.size();
                types.add(viewRef);
            }
            List<DataBindingItem> children = dataBindingItem.getChildren();
            int count = dataBindingItem.getCount();
            // if there are children, we use the count as a repeat count for the children.
            if (children.size() > 0) {
                count = 1;
            }
            int index = typeCount[typeIndex];
            typeCount[typeIndex] += count;
            for (int k = 0; k < count; k++) {
                AdapterItem item = new AdapterItem(dataBindingItem, typeIndex, mItems.size(), index++);
                mItems.add(item);
                if (children.size() > 0) {
                    createItems(dataBindingItem, depth + 1);
                }
            }
        }
    }
}
Also used : DataBindingItem(com.android.ide.common.rendering.api.DataBindingItem) ResourceReference(com.android.ide.common.rendering.api.ResourceReference)

Example 20 with ResourceReference

use of com.android.ide.common.rendering.api.ResourceReference in project android_frameworks_base by AOSPA.

the class RenderSessionImpl method postInflateProcess.

/**
     * Post process on a view hierarchy that was just inflated.
     * <p/>
     * At the moment this only supports TabHost: If {@link TabHost} is detected, look for the
     * {@link TabWidget}, and the corresponding {@link FrameLayout} and make new tabs automatically
     * based on the content of the {@link FrameLayout}.
     * @param view the root view to process.
     * @param layoutlibCallback callback to the project.
     * @param skip the view and it's children are not processed.
     */
// For the use of Pair
@SuppressWarnings("deprecation")
private void postInflateProcess(View view, LayoutlibCallback layoutlibCallback, View skip) throws PostInflateException {
    if (view == skip) {
        return;
    }
    if (view instanceof TabHost) {
        setupTabHost((TabHost) view, layoutlibCallback);
    } else if (view instanceof QuickContactBadge) {
        QuickContactBadge badge = (QuickContactBadge) view;
        badge.setImageToDefault();
    } else if (view instanceof AdapterView<?>) {
        // get the view ID.
        int id = view.getId();
        BridgeContext context = getContext();
        // get a ResourceReference from the integer ID.
        ResourceReference listRef = context.resolveId(id);
        if (listRef != null) {
            SessionParams params = getParams();
            AdapterBinding binding = params.getAdapterBindings().get(listRef);
            // if there was no adapter binding, trying to get it from the call back.
            if (binding == null) {
                binding = layoutlibCallback.getAdapterBinding(listRef, context.getViewKey(view), view);
            }
            if (binding != null) {
                if (view instanceof AbsListView) {
                    if ((binding.getFooterCount() > 0 || binding.getHeaderCount() > 0) && view instanceof ListView) {
                        ListView list = (ListView) view;
                        boolean skipCallbackParser = false;
                        int count = binding.getHeaderCount();
                        for (int i = 0; i < count; i++) {
                            Pair<View, Boolean> pair = context.inflateView(binding.getHeaderAt(i), list, false, skipCallbackParser);
                            if (pair.getFirst() != null) {
                                list.addHeaderView(pair.getFirst());
                            }
                            skipCallbackParser |= pair.getSecond();
                        }
                        count = binding.getFooterCount();
                        for (int i = 0; i < count; i++) {
                            Pair<View, Boolean> pair = context.inflateView(binding.getFooterAt(i), list, false, skipCallbackParser);
                            if (pair.getFirst() != null) {
                                list.addFooterView(pair.getFirst());
                            }
                            skipCallbackParser |= pair.getSecond();
                        }
                    }
                    if (view instanceof ExpandableListView) {
                        ((ExpandableListView) view).setAdapter(new FakeExpandableAdapter(listRef, binding, layoutlibCallback));
                    } else {
                        ((AbsListView) view).setAdapter(new FakeAdapter(listRef, binding, layoutlibCallback));
                    }
                } else if (view instanceof AbsSpinner) {
                    ((AbsSpinner) view).setAdapter(new FakeAdapter(listRef, binding, layoutlibCallback));
                }
            }
        }
    } else if (view instanceof ViewGroup) {
        mInflater.postInflateProcess(view);
        ViewGroup group = (ViewGroup) view;
        final int count = group.getChildCount();
        for (int c = 0; c < count; c++) {
            View child = group.getChildAt(c);
            postInflateProcess(child, layoutlibCallback, skip);
        }
    }
}
Also used : SessionParams(com.android.ide.common.rendering.api.SessionParams) TabHost(android.widget.TabHost) ViewGroup(android.view.ViewGroup) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) AbsListView(android.widget.AbsListView) FakeAdapter(com.android.layoutlib.bridge.impl.binding.FakeAdapter) FakeExpandableAdapter(com.android.layoutlib.bridge.impl.binding.FakeExpandableAdapter) 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) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) ExpandableListView(android.widget.ExpandableListView) QuickContactBadge(android.widget.QuickContactBadge) AdapterBinding(com.android.ide.common.rendering.api.AdapterBinding) AbsSpinner(android.widget.AbsSpinner) AdapterView(android.widget.AdapterView) ResourceReference(com.android.ide.common.rendering.api.ResourceReference) ExpandableListView(android.widget.ExpandableListView)

Aggregations

ResourceReference (com.android.ide.common.rendering.api.ResourceReference)28 ViewGroup (android.view.ViewGroup)12 BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)10 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)9 AdapterBinding (com.android.ide.common.rendering.api.AdapterBinding)7 DataBindingItem (com.android.ide.common.rendering.api.DataBindingItem)7 View (android.view.View)6 AbsListView (android.widget.AbsListView)6 AbsSpinner (android.widget.AbsSpinner)6 AdapterView (android.widget.AdapterView)6 Checkable (android.widget.Checkable)6 ExpandableListView (android.widget.ExpandableListView)6 ImageView (android.widget.ImageView)6 ListView (android.widget.ListView)6 QuickContactBadge (android.widget.QuickContactBadge)6 TabHost (android.widget.TabHost)6 TextView (android.widget.TextView)6 SessionParams (com.android.ide.common.rendering.api.SessionParams)6 FakeAdapter (com.android.layoutlib.bridge.impl.binding.FakeAdapter)6 FakeExpandableAdapter (com.android.layoutlib.bridge.impl.binding.FakeExpandableAdapter)6