commonsguy / cwac-merge Goto Github PK
View Code? Open in Web Editor NEWCommonsWare Android Components: MergeAdapter
Home Page: http://commonsware.com/cwac
License: Apache License 2.0
CommonsWare Android Components: MergeAdapter
Home Page: http://commonsware.com/cwac
License: Apache License 2.0
I create a view with MergeAdapter containing some other single views. for example a header view, a list view etc.
My problem is, if the list is empty, i do not merge it to the adapter, but then, the created MergeAdapter view is smaller then my screen and i have an ugly "grey" are on the bottom on the screen.
Is there a way do add a background to the adapter itself? Or do you have any hints how i can "spread" my view to fill the complete screen?
I note that hasStableIds()
uses the base implementation, which always returns false. Would it be useful to determine ID stability from the merged adapters instead?
IGNORE_ITEM_VIEW_TYPE happens to work for the first merged piece, but fails on second and subsequent ones. We need to avoid adding in the offsets for IGNORE_ITEM_VIEW_TYPE.
After adding a view with addView(view, false)
or addView(view)
, the standard ListView dividers do not appear before or after the added view. Adding the view with addView(view, true)
shows the dividers.
I am in the process of upgrading an app to use Picasso but was running into OOME on older 2.x devices when scrolling rapidly.
It seems the Picasso view recycling/cancelling and MergeAdapter don't play well together.
File->Import->select_project_and_demo->finish
Run MergeAdapterDemo
Stacktrace:
http://pastebin.com/jjNYJkHc
Hi,
We are using cwac-endless library in our application and noticed that APK built with Android Studio/Gradle has more permissions than we declared in our AndroidManifest.xml.
In "...\build\outputs\apk" manifest merger generates files (manifest-merger-[debug|release]-report.txt) with information why and from each element was added to the final manifest. In these files you can see something like below:
android:uses-permission#android.permission.READ_PHONE_STATE
IMPLIED from AndroidManifest.xml:2:1 reason: com.commonsware.cwac.endless has a targetSdkVersion < 4
which is true because CWAC's manifest doesn't specify minSdkVersion or targetSdkVersion so both defaults to 1.
Steps to reproduce:
It would great if you can specify some minimal targetSdkVersion like "4" to prevent manifest merger from automatically adding permissions which have nothing in common with MergeAdapter :)
Thanks.
Shubham Bansal
Zalando
Hi.
We use MergeAdapter in one of our application and noticed that APK built with Android Studio/Gradle has more permissions than we declared in our AndroidManifest.xml.
In "...\build\outputs\apk" manifest merger generates files (manifest-merger-[debug|release]-report.txt) with information why and from each element was added to the final manifest. In these files you can see something like below:
android:uses-permission#android.permission.WRITE_EXTERNAL_STORAGE
IMPLIED from AndroidManifest.xml:2:1 reason: com.commonsware.cwac.merge has a targetSdkVersion < 4android:uses-permission#android.permission.READ_PHONE_STATE
IMPLIED from AndroidManifest.xml:2:1 reason: com.commonsware.cwac.merge has a targetSdkVersion < 4android:uses-permission#android.permission.READ_EXTERNAL_STORAGE
IMPLIED from AndroidManifest.xml:2:1 reason: com.commonsware.cwac.merge requested WRITE_EXTERNAL_STORAGE
which is true because CWAC's manifest doesn't specify minSdkVersion or targetSdkVersion so both defaults to 1.
Steps to reproduce:
It would great if you can specify some minimal targetSdkVersion like "4" to prevent manifest merger from automatically adding permissions which have nothing in common with MergeAdapter :)
Thanks.
if due to stupidity of programmer the adapter is requesting a view to be displayed in an invalid position i.e. position > getCount() == true
the method returns null and passes the issue to other places in the system
In my case, there was a location in which I forgot to call notifyDatasetInvalidated()
when the adapter cleared the data and scrolling in the invalid list wold cause an issue in android.widget.HeaderViewListAdapter.isEnabled
instead of throwing it in the initial getView.
I suggest adding a validation of position and an exception instead of returning null and letting the system crash.
Hello,
I'm unable to use wildcard version in my build.gradle
. As an example check my repo for facebook android sdk. You can use github pages for hosting and this script to generate directory listings (more details here)
I have a fragment where I am calling addView before calling addAdapter. The view I am adding contains an EditText however whenever I click on the EditText it doesn't appear be to focused, the Keyboard comes up but the EditText won't accept any input.
Not sure if this is an issue or if the MergeAdapter was not geared towards this kind of use? But any suggestion would be much appreciated.
Could not find com.commonsware.cwac:merge:1.1.1.
I would be great if there were maven artifacts of this project available. The new gradle build system makes it much easier to use these and adding the .jar files directly to the repositories is not really a clean way of using the component.
Hi Mark,
I found your stellar merge lib, which will make all my ListView dreams come true, but I'm experiencing a crash when calling addView() with a view (LinearLayout) that has this line applied to it:
mLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1));
This is the crash:
09-19 19:05:04.385: ERROR/ACRA(18343): fatal error : android.widget.LinearLayout$LayoutParams
09-19 19:05:04.385: ERROR/ACRA(18343): java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
09-19 19:05:04.385: ERROR/ACRA(18343): at android.widget.ListView.measureScrapChild(ListView.java:1135)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.widget.ListView.measureHeightOfChildren(ListView.java:1218)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.widget.ListView.onMeasure(ListView.java:1127)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.view.View.measure(View.java:8313)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.view.View.measure(View.java:8313)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.view.View.measure(View.java:8313)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.view.View.measure(View.java:8313)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.os.Handler.dispatchMessage(Handler.java:99)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.os.Looper.loop(Looper.java:130)
09-19 19:05:04.385: ERROR/ACRA(18343): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-19 19:05:04.385: ERROR/ACRA(18343): at java.lang.reflect.Method.invokeNative(Native Method)
09-19 19:05:04.385: ERROR/ACRA(18343): at java.lang.reflect.Method.invoke(Method.java:507)
09-19 19:05:04.385: ERROR/ACRA(18343): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-19 19:05:04.385: ERROR/ACRA(18343): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-19 19:05:04.385: ERROR/ACRA(18343): at dalvik.system.NativeStart.main(Native Method)
If I remove that line, things start working fine. Anything you can do?
Thank you.
Edit: I realize the exception is raised from within the Android SDK - what am I doing wrong?
I'm getting an error on my tablet running Android Kitkat 4.4.2... (Runs perfectly on my Lollipop phone).
Seems like the my layout heading is being cast incorrectly... When I remove the header, it runs perfectly.
Here is how I am creating my header...
albumHeaderView = inflater.inflate(R.layout.search_album_header, container, false);
And here is how I'm adding it to the adapter.
mergeAdapter = new MergeAdapter();
mergeAdapter.addView(artistHeaderView);
This is the error:
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41709c08)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.ListView.setupChild(ListView.java:1839)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.ListView.makeAndAddView(ListView.java:1806)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.ListView.fillDown(ListView.java:697)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.ListView.fillFromTop(ListView.java:763)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.ListView.layoutChildren(ListView.java:1641)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.AbsListView.onLayout(AbsListView.java:2528)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.view.View.layout(View.java:15655)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.view.ViewGroup.layout(ViewGroup.java:4856)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.view.View.layout(View.java:15655)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.view.ViewGroup.layout(ViewGroup.java:4856)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.view.View.layout(View.java:15655)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.view.ViewGroup.layout(ViewGroup.java:4856)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.view.View.layout(View.java:15655)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.view.ViewGroup.layout(ViewGroup.java:4856)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
11-10 16:56:26.352 1644-1644/com.denite.shuffleemup W/System.err: at android.view.View.layout(View.java:15655)
11-10 16:56:26.357 1644-1644/com.denite.shuffleemup W/System.err: at android.view.ViewGroup.layout(ViewGroup.java:4856)
11-10 16:56:26.357 1644-1644/com.denite.shuffleemup W/System.err: at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:907)
11-10 16:56:26.357 1644-1644/com.denite.shuffleemup W/System.err: at android.view.View.layout(View.java:15655)
11-10 16:56:26.357 1644-1644/com.denite.shuffleemup W/System.err: at android.view.ViewGroup.layout(ViewGroup.java:4856)
11-10 16:56:26.357 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
11-10 16:56:26.357 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
11-10 16:56:26.357 1644-1644/com.denite.shuffleemup W/System.err: at android.view.View.layout(View.java:15655)
11-10 16:56:26.357 1644-1644/com.denite.shuffleemup W/System.err: at android.view.ViewGroup.layout(ViewGroup.java:4856)
11-10 16:56:26.357 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
11-10 16:56:26.357 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
11-10 16:56:26.357 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
11-10 16:56:26.357 1644-1644/com.denite.shuffleemup W/System.err: at android.view.View.layout(View.java:15655)
11-10 16:56:26.357 1644-1644/com.denite.shuffleemup W/System.err: at android.view.ViewGroup.layout(ViewGroup.java:4856)
11-10 16:56:26.357 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
11-10 16:56:26.357 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
11-10 16:56:26.357 1644-1644/com.denite.shuffleemup W/System.err: at android.view.View.layout(View.java:15655)
11-10 16:56:26.357 1644-1644/com.denite.shuffleemup W/System.err: at android.view.ViewGroup.layout(ViewGroup.java:4856)
11-10 16:56:26.357 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.view.View.layout(View.java:15655)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.view.ViewGroup.layout(ViewGroup.java:4856)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.view.View.layout(View.java:15655)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.view.ViewGroup.layout(ViewGroup.java:4856)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2287)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2007)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1231)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6459)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.view.Choreographer.doCallbacks(Choreographer.java:603)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.view.Choreographer.doFrame(Choreographer.java:573)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.os.Looper.loop(Looper.java:157)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5350)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
11-10 16:56:26.362 1644-1644/com.denite.shuffleemup W/System.err: at dalvik.system.NativeStart.main(Native Method)
Hey, first thanks a lot with your library it's really helpful.
I'm currently having an issue. I'm not sure if it's a bug related to cwac-merge but it could be.
I've got a view with clickable widgets in it. I'm adding this view to my MergeAdapter and sometimes onClick events don't get fired until I scroll my ListView. If I click multiple times on a button, these events will get fired as many times after the scroll.
I'm not posting any code, it's as simple as it's described. I'm just adding this view to my mergeadapter and setting onclicklistener from my custom view class. I also have onItemClick listeners but I removed them and the bug was reproductible.
Have you ever been in this situation?
Thanks
Using maven to add cwac-merge as a dependency to an Android app, the following error is thrown when resolving the newly added dependency:
[ERROR] Failed to execute goal on project [project_name]: Could not resolve dependencies for project [app_name]: Could not find artifact com.commonsware.cwac:sacklist:jar:1.0.+ in commonsware (http://repo.commonsware.com.s3.amazonaws.com) -> [Help 1]
The problem here is that merge-1.1.1.pom points to cwac-sacklist as a dependency, but doesn't define the packaging type. As such, maven defaults to looking for a jar file (as illustrated by the error message above). But, as we can see in the repo, sacklist is only available as aar package.
Specifying the packaging type (aar
) for the nested cwac-sacklist dependency solves the issue. That is, with the pom file below, the nested dependency can be resolved correctly:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.commonsware.cwac</groupId>
<artifactId>merge</artifactId>
<version>1.1.1</version>
<packaging>aar</packaging>
<dependencies>
<dependency>
<groupId>com.commonsware.cwac</groupId>
<artifactId>sacklist</artifactId>
<version>1.0.+</version>
<type>aar</type>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
(Note: only change is the added line that says: <type>aar</type>
)
It'd be great if the pom could be updated to include the aar packaging type for the sacklist dependency, allowing maven to correctly resolve it (or alternatively, publish a jar
package too). I haven't tested with Gradle (yet), but I suspect it may default to aar
packaging?
I am using MergeAdapter
in Fragment
s which are used in a ViewPager
. Sometimes when I am switching between pages I see that the view which is present in SackOfViewsAdapter
and is not active becomes null, which results in empty layouts. The fragments which are present in ViewPager doesn't get destroyed completely though, because the onCreate()
method of the fragment is not getting called. It's of worth to mention that the fragments are not retained and I tested both with FragmentPagerAdapter
and FragmentStatePagerAdapter
.
I solved this issue by rewriting SackOfViewsAdapter
and adding a method to replace views. Then when I am setting the adapter active again, I check if the view is nulled, to replace if necessary.
I suppose it's handy to have a functionality like this baked into the library.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.