diff options
author | Xavier Ducrohet <xav@android.com> | 2011-04-01 14:34:20 -0700 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2011-04-01 14:34:20 -0700 |
commit | 0e6eb1f1ee20e38c5693552ca6de2294105edee7 (patch) | |
tree | 5e343bc2b3e2fb95ac1e2c0f265ccc482c65fb94 /layoutlib_api | |
parent | 0016c58e4876ff16aa69c2363fb3736aaf3ffd78 (diff) | |
parent | c192279ab98f022587c1fc1f285dc7abd191d76d (diff) | |
download | sdk-0e6eb1f1ee20e38c5693552ca6de2294105edee7.zip sdk-0e6eb1f1ee20e38c5693552ca6de2294105edee7.tar.gz sdk-0e6eb1f1ee20e38c5693552ca6de2294105edee7.tar.bz2 |
Merge "Add a way to get the adapter binding through the project callback."
Diffstat (limited to 'layoutlib_api')
3 files changed, 111 insertions, 82 deletions
diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/AdapterBinding.java b/layoutlib_api/src/com/android/ide/common/rendering/api/AdapterBinding.java new file mode 100644 index 0000000..52fbdcb --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/AdapterBinding.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.ide.common.rendering.api; + +import java.util.ArrayList; +import java.util.List; + +/** + * Describe the content of the dynamic android.widget.Adapter used to fill + * android.widget.AdapterView + */ +public class AdapterBinding { + + /** + * An AdapterItemReference. On top of being a {@link ResourceReference}, it contains how many + * items of this type the data binding should display. + */ + public static class AdapterItemReference extends ResourceReference { + private final int mCount; + + public AdapterItemReference(String name, boolean platformLayout, int count) { + super(name, platformLayout); + mCount = count; + } + + public AdapterItemReference(String name, boolean platformLayout) { + this(name, platformLayout, 1); + } + + public AdapterItemReference(String name) { + this(name, false /*platformLayout*/, 1); + } + + public int getCount() { + return mCount; + } + } + + private final int mRepeatCount; + private final List<ResourceReference> mHeaders = new ArrayList<ResourceReference>(); + private final List<AdapterItemReference> mItems = new ArrayList<AdapterItemReference>(); + private final List<ResourceReference> mFooters = new ArrayList<ResourceReference>(); + + public AdapterBinding(int repeatCount) { + mRepeatCount = repeatCount; + } + + public int getRepeatCount() { + return mRepeatCount; + } + + public void addHeader(ResourceReference layoutInfo) { + mHeaders.add(layoutInfo); + } + + public int getHeaderCount() { + return mHeaders.size(); + } + + public ResourceReference getHeaderAt(int index) { + return mHeaders.get(index); + } + + public void addItem(AdapterItemReference itemInfo) { + mItems.add(itemInfo); + } + + public int getItemCount() { + return mItems.size(); + } + + public AdapterItemReference getItemAt(int index) { + return mItems.get(index); + } + + public void addFooter(ResourceReference layoutInfo) { + mFooters.add(layoutInfo); + } + + public int getFooterCount() { + return mFooters.size(); + } + + public ResourceReference getFooterAt(int index) { + return mFooters.get(index); + } +} diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/IProjectCallback.java b/layoutlib_api/src/com/android/ide/common/rendering/api/IProjectCallback.java index 161a1a5..1a16c48 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/IProjectCallback.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/IProjectCallback.java @@ -88,4 +88,14 @@ public interface IProjectCallback { String getAdapterItemValue(ResourceReference adapterView, ResourceReference itemRef, int fullPosition, int typePosition, ResourceReference viewRef, String viewClass); + + /** + * Returns an adapter binding for a given adapter view. + * This is only called if {@link SessionParams} does not have an {@link AdapterBinding} for + * the given {@link ResourceReference} already. + * + * @param adapterView the adapter view to return the adapter binding for. + * @return an adapter binding for the given view or null if there's no data. + */ + AdapterBinding getAdapterBinding(ResourceReference adapterView); } diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/SessionParams.java b/layoutlib_api/src/com/android/ide/common/rendering/api/SessionParams.java index e80378e..f4f6b5c 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/SessionParams.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/SessionParams.java @@ -18,10 +18,8 @@ package com.android.ide.common.rendering.api; import com.android.resources.Density; -import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; /** @@ -52,86 +50,6 @@ public class SessionParams extends RenderParams { } } - /** - * An AdapterItemReference. On top of being a {@link ResourceReference}, it contains how many - * items of this type the data binding should display. - */ - public static class AdapterItemReference extends ResourceReference { - private final int mCount; - - public AdapterItemReference(String name, boolean platformLayout, int count) { - super(name, platformLayout); - mCount = count; - } - - public AdapterItemReference(String name, boolean platformLayout) { - this(name, platformLayout, 1); - } - - public AdapterItemReference(String name) { - this(name, false /*platformLayout*/, 1); - } - - public int getCount() { - return mCount; - } - } - - /** - * Describe the content of the dynamic android.widget.Adapter used to fill - * android.widget.AdapterView - */ - public static class AdapterBinding { - private final int mRepeatCount; - private final List<ResourceReference> mHeaders = new ArrayList<ResourceReference>(); - private final List<AdapterItemReference> mItems = new ArrayList<AdapterItemReference>(); - private final List<ResourceReference> mFooters = new ArrayList<ResourceReference>(); - - public AdapterBinding(int repeatCount) { - mRepeatCount = repeatCount; - } - - public int getRepeatCount() { - return mRepeatCount; - } - - public void addHeader(ResourceReference layoutInfo) { - mHeaders.add(layoutInfo); - } - - public int getHeaderCount() { - return mHeaders.size(); - } - - public ResourceReference getHeaderAt(int index) { - return mHeaders.get(index); - } - - public void addItem(AdapterItemReference itemInfo) { - mItems.add(itemInfo); - } - - public int getItemCount() { - return mItems.size(); - } - - public AdapterItemReference getItemAt(int index) { - return mItems.get(index); - } - - public void addFooter(ResourceReference layoutInfo) { - mFooters.add(layoutInfo); - } - - public int getFooterCount() { - return mFooters.size(); - } - - public ResourceReference getFooterAt(int index) { - return mFooters.get(index); - } - } - private final ILayoutPullParser mLayoutDescription; private final RenderingMode mRenderingMode; private boolean mLayoutOnly = false; |