[
  {
    "path": ".gitignore",
    "content": "# built application files\n*.apk\n*.ap_\n\n# files for the dex VM\n*.dex\n\n# Java class files\n*.class\n\n# generated files\nbin/\ngen/\n\n# Local configuration file (sdk path, etc)\nlocal.properties\n\n# Eclipse project files\n.classpath\n.project\n"
  },
  {
    "path": "AndroidManifest.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    package=\"com.sothree.slidinguppaneldemo\"\n    android:versionCode=\"1\"\n    android:versionName=\"1.0\" >\n\n    <uses-sdk\n        android:minSdkVersion=\"11\"\n        android:targetSdkVersion=\"17\" />\n    \n    <uses-permission android:name=\"android.permission.GET_ACCOUNTS\" />\n    <uses-permission android:name=\"android.permission.READ_CONTACTS\" />   \n\n    <application\n        android:allowBackup=\"true\"\n        android:icon=\"@drawable/ic_launcher\"\n        android:label=\"@string/app_name\"\n        android:theme=\"@style/AppTheme\" >\n        <activity\n            android:name=\"com.sothree.multiitemrowlistadapter.demo.DemoActivity\"\n            android:label=\"@string/app_name\" >\n            <intent-filter>\n                <action android:name=\"android.intent.action.MAIN\" />\n\n                <category android:name=\"android.intent.category.LAUNCHER\" />\n            </intent-filter>\n        </activity>\n        \n    </application>\n\n</manifest>\n"
  },
  {
    "path": "LICENSE.txt",
    "content": "                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "README.md",
    "content": "Android Multi Item Row ListAdapter\n==================================\n### An Easy Way to Make Your ListView's Look Amazing on Tablets\nWith the launch of the tablet version of [Umano](http://umanoapp.com) [Android app](https://play.google.com/store/apps/details?id=com.sothree.umano) we decided to open-source another component, which allows you to very quickly make your ListViews and ListActivities look amazing on tablets and phablets by placing multiple items of your ListAdapter in each row in a ListView. Umano Team <3 Open Source.\n\nAs seen in Umano ([http://umanoapp.com](http://umanoapp.com)):\n\n![MultiItemRowListAdapter](https://raw.github.com/umano/MultiItemRowListAdapter/master/multiitem.png)\n\n### Usage\n\nAll you need to do is wrap your original ListAdapter using a `MultiItemRowListAdapter`:\n```java\n    int spacing = (int)getResources().getDimension(R.dimen.spacing);\n    int itemsPerRow = getResources().getInteger(R.integer.items_per_row);\n    MultiItemRowListAdapter wrapperAdapter = new MultiItemRowListAdapter(this, mAdapter, itemsPerRow, spacing);\n    setListAdapter(wrapperAdapter);\n```\nAs you can see the constructor for `MultiItemRowListAdapter` takes two parameters `itemsPerRow` and `spacing`. The first one is just the number of items from the original adapter to place on each row, and the second one is the cell spacing in pixels between the items. It's really convenient to specify the parameters in xml, so that you can easily vary the number of items per row on different screen orientations and sizes.\nres/values/integers.xml - phone portrait (1 items per row)\n```xml\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <integer name=\"items_per_row\">1</integer>\n</resources>\n```\nres/values-land/integers.xml - phone landscape (2 items per row)\n```xml\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <integer name=\"items_per_row\">2</integer>\n</resources>\n```\nres/values-sw600/integers.xml - 7' tablet portrait (2 items per row)\n```xml\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <integer name=\"items_per_row\">2</integer>\n</resources>\n```\nres/values-sw600-land/integers.xml - 7' tablet landscape (3 items per row)\n```xml\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <integer name=\"items_per_row\">3</integer>\n</resources>\n```\n\n### Requrements\nTested on Android 2.2+\n\n### Licence\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this work except in compliance with the License.\nYou may obtain a copy of the License in the LICENSE file, or at:\n\n  [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n"
  },
  {
    "path": "proguard-project.txt",
    "content": "# To enable ProGuard in your project, edit project.properties\n# to define the proguard.config property as described in that file.\n#\n# Add project specific ProGuard rules here.\n# By default, the flags in this file are appended to flags specified\n# in ${sdk.dir}/tools/proguard/proguard-android.txt\n# You can edit the include path and order by changing the ProGuard\n# include property in project.properties.\n#\n# For more details, see\n#   http://developer.android.com/guide/developing/tools/proguard.html\n\n# Add any project specific keep options here:\n\n# If your project uses WebView with JS, uncomment the following\n# and specify the fully qualified class name to the JavaScript interface\n# class:\n#-keepclassmembers class fqcn.of.javascript.interface.for.webview {\n#   public *;\n#}\n"
  },
  {
    "path": "project.properties",
    "content": "# This file is automatically generated by Android Tools.\n# Do not modify this file -- YOUR CHANGES WILL BE ERASED!\n#\n# This file must be checked in Version Control Systems.\n#\n# To customize properties used by the Ant build system edit\n# \"ant.properties\", and override values to adapt the script to your\n# project structure.\n#\n# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):\n#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt\n\n# Project target.\ntarget=android-17\n"
  },
  {
    "path": "res/drawable/above_shadow.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<shape xmlns:android=\"http://schemas.android.com/apk/res/android\">   \n    <gradient\n        android:startColor=\"#20000000\"\n        android:endColor=\"@android:color/transparent\"\n        android:angle=\"90\" >\n    </gradient>\n</shape>"
  },
  {
    "path": "res/drawable/list_selector.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<selector xmlns:android=\"http://schemas.android.com/apk/res/android\" >\n    <item android:state_pressed=\"true\"\n          android:drawable=\"@color/app_background\" /> <!-- pressed -->\n    <item android:drawable=\"@android:color/white\" /> <!-- default -->\n</selector>"
  },
  {
    "path": "res/layout/activity_demo.xml",
    "content": "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:orientation=\"vertical\" >\n\n    <ListView\n        android:id=\"@android:id/list\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"0dp\"\n        android:divider=\"@null\"        \n        android:listSelector=\"@color/app_background\"\n        android:dividerHeight=\"0dp\"       \n        android:layout_weight=\"1\"/>\n\n    <TextView\n        android:id=\"@android:id/empty\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\n        android:gravity=\"center\"\n\t\tandroid:textSize=\"16sp\"\n        android:text=\"Loading...\" />\n\n</LinearLayout>"
  },
  {
    "path": "res/layout/include_list_item_contact.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"wrap_content\"\n    android:baselineAligned=\"false\"\n    android:orientation=\"horizontal\" \n    android:gravity=\"center_vertical\"\n    android:focusable=\"false\"\n    android:focusableInTouchMode=\"false\"\n    android:duplicateParentState=\"false\"\n    android:clickable=\"true\" \n    android:background=\"@drawable/list_selector\">\n\n    <ImageView\n        android:id=\"@+id/image\"\n        android:layout_width=\"40dp\"\n        android:layout_height=\"40dp\"\n        android:layout_gravity=\"top\"\n        android:layout_margin=\"10dp\"\n        android:background=\"@drawable/ic_launcher\"\n        android:contentDescription=\"@string/app_name\"\n        android:scaleType=\"centerCrop\"/>\n\n    <TextView\n        android:id=\"@+id/lbl_contact_name\"\n        android:layout_width=\"0dp\"\n        android:layout_height=\"wrap_content\"\n        android:layout_gravity=\"center_vertical\"\n        android:layout_weight=\"1\"\n        android:layout_marginRight=\"10dp\"\n        android:ellipsize=\"end\"\n        android:singleLine=\"true\"\n        android:duplicateParentState=\"true\"\n        android:textIsSelectable=\"false\"\n        android:textSize=\"16sp\" />   \n\n</LinearLayout>"
  },
  {
    "path": "res/menu/demo.xml",
    "content": "<menu xmlns:android=\"http://schemas.android.com/apk/res/android\" >\n\n    <item\n        android:id=\"@+id/action_settings\"\n        android:orderInCategory=\"100\"\n        android:showAsAction=\"never\"\n        android:title=\"@string/action_settings\"/>\n\n</menu>\n"
  },
  {
    "path": "res/values/colors.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <color name=\"app_background\">#e8e8e8</color>    \n</resources>\n"
  },
  {
    "path": "res/values/dimen.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <dimen name=\"spacing\">10dp</dimen>   \n</resources>"
  },
  {
    "path": "res/values/integers.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <integer name=\"items_per_row\">1</integer>\n</resources>"
  },
  {
    "path": "res/values/strings.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n\n    <string name=\"app_name\">MultiItemRowListAdapter Demo</string>\n    <string name=\"action_settings\">Settings</string>\n    <string name=\"hello_world\">Hello world!</string>\n\n</resources>\n"
  },
  {
    "path": "res/values/styles.xml",
    "content": "<resources>\n\n    <!--\n        Base application theme, dependent on API level. This theme is replaced\n        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.\n    -->\n    <style name=\"AppBaseTheme\" parent=\"android:Theme.Light\">\n        <!--\n            Theme customizations available in newer API levels can go in\n            res/values-vXX/styles.xml, while customizations related to\n            backward-compatibility can go here.\n        -->\n\t\t<item name=\"android:windowActionBarOverlay\">true</item>        \n    </style>\n\n    <!-- Application theme. -->\n    <style name=\"AppTheme\" parent=\"AppBaseTheme\">\n        <item name=\"android:windowBackground\">@color/app_background</item>\n    </style>\n\n</resources>\n"
  },
  {
    "path": "res/values-land/integers.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <integer name=\"items_per_row\">2</integer>\n</resources>"
  },
  {
    "path": "res/values-sw600dp/integers.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <integer name=\"items_per_row\">2</integer>\n</resources>"
  },
  {
    "path": "res/values-sw600dp-land/integers.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <integer name=\"items_per_row\">3</integer>\n</resources>"
  },
  {
    "path": "res/values-v11/styles.xml",
    "content": "<resources>\n\n    <!--\n        Base application theme for API 11+. This theme completely replaces\n        AppBaseTheme from res/values/styles.xml on API 11+ devices.\n    -->\n    <style name=\"AppBaseTheme\" parent=\"android:Theme.Holo.Light\">\n        <!-- API 11 theme customizations can go here. -->\n    </style>\n\n</resources>\n"
  },
  {
    "path": "res/values-v14/styles.xml",
    "content": "<resources>\n\n    <!--\n        Base application theme for API 14+. This theme completely replaces\n        AppBaseTheme from BOTH res/values/styles.xml and\n        res/values-v11/styles.xml on API 14+ devices.\n    -->\n    <style name=\"AppBaseTheme\" parent=\"android:Theme.Holo.Light.DarkActionBar\">\n        <!-- API 14 theme customizations can go here. -->\n    </style>\n\n</resources>\n"
  },
  {
    "path": "src/com/sothree/multiitemrowlistadapter/MultiItemRowListAdapter.java",
    "content": "package com.sothree.multiitemrowlistadapter;\n\nimport java.lang.ref.WeakReference;\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport android.content.Context;\nimport android.database.DataSetObserver;\nimport android.view.View;\nimport android.view.ViewGroup;\nimport android.view.ViewGroup.LayoutParams;\nimport android.widget.AbsListView;\nimport android.widget.LinearLayout;\nimport android.widget.ListAdapter;\nimport android.widget.WrapperListAdapter;\n\npublic class MultiItemRowListAdapter implements WrapperListAdapter {\n    private final ListAdapter mAdapter;\n    private final int mItemsPerRow;\n    private final int mCellSpacing;\n    private final WeakReference<Context> mContextReference;\n    private final LinearLayout.LayoutParams mItemLayoutParams;\n    private final AbsListView.LayoutParams mRowLayoutParams;\n\n    public MultiItemRowListAdapter(Context context, ListAdapter adapter, int itemsPerRow, int cellSpacing) {\n        if (itemsPerRow <= 0) {\n            throw new IllegalArgumentException(\"Number of items per row must be positive\");\n        }\n        mContextReference = new WeakReference<Context>(context);\n        mAdapter = adapter;\n        mItemsPerRow = itemsPerRow;\n        mCellSpacing = cellSpacing;\n\n        mItemLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT);\n        mItemLayoutParams.setMargins(cellSpacing, cellSpacing, 0, 0);\n        mItemLayoutParams.weight = 1;\n        mRowLayoutParams = new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);\n    }\n\n    @Override\n    public boolean isEmpty() {\n        return (mAdapter == null || mAdapter.isEmpty());\n    }\n\n    public int getItemsPerRow() {\n        return mItemsPerRow;\n    }\n\n    @Override\n    public int getCount() {\n        if (mAdapter != null) {\n            return (int)Math.ceil(1.0f * mAdapter.getCount() / mItemsPerRow);\n        }\n        return 0;\n    }\n\n    @Override\n    public boolean areAllItemsEnabled() {\n        if (mAdapter != null) {\n            return mAdapter.areAllItemsEnabled();\n        } else {\n            return true;\n        }\n    }\n\n    @Override\n    public boolean isEnabled(int position) {\n        if (mAdapter != null) {\n            // the cell is enabled if at least one item is enabled\n            boolean enabled = false;\n            for (int i = 0; i < mItemsPerRow; ++i) {\n                int p = position * mItemsPerRow + i;\n                if (p < mAdapter.getCount()) {\n                    enabled |= mAdapter.isEnabled(p);\n                }\n            }\n            return enabled;\n        }\n        return true;\n    }\n\n    @Override\n    public Object getItem(int position) {\n        if (mAdapter != null) {\n            List<Object> items = new ArrayList<Object>(mItemsPerRow);\n            for (int i = 0; i < mItemsPerRow; ++i) {\n                int p = position * mItemsPerRow + i;\n                if (p < mAdapter.getCount()) {\n                    items.add(mAdapter.getItem(p));\n                }\n            }\n            return items;\n        }\n        return null;\n    }\n\n    @Override\n    public long getItemId(int position) {\n        if (mAdapter != null) {\n            return position;\n        }\n        return -1;\n    }\n\n    @Override\n    public boolean hasStableIds() {\n        if (mAdapter != null) {\n            return mAdapter.hasStableIds();\n        }\n        return false;\n    }\n\n    @Override\n    public View getView(int position, View convertView, ViewGroup parent) {\n        Context c = mContextReference.get();\n        if (c == null || mAdapter == null) return null;\n\n        LinearLayout view = null;\n        if (convertView == null\n                || !(convertView instanceof LinearLayout)\n                || !((Integer)convertView.getTag()).equals(mItemsPerRow)) {\n            // create a linear Layout\n            view = new LinearLayout(c);\n            view.setPadding(0, 0, mCellSpacing, 0);\n            view.setLayoutParams(mRowLayoutParams);\n            view.setOrientation(LinearLayout.HORIZONTAL);\n            view.setBaselineAligned(false);\n            view.setTag(Integer.valueOf(mItemsPerRow));\n        } else {\n            view = (LinearLayout) convertView;\n        }\n\n        for (int i = 0; i < mItemsPerRow; ++i) {\n            View subView = i < view.getChildCount() ? view.getChildAt(i) : null;\n            int p = position * mItemsPerRow + i;\n\n            View newView = subView;\n            if (p < mAdapter.getCount()) {\n            \tif (subView instanceof PlaceholderView){\n            \t\tview.removeView(subView);\n            \t\tsubView = null;\n            \t}\n                newView = mAdapter.getView(p, subView, view);\n            } else if (subView == null || !(subView instanceof PlaceholderView)) {\n                newView = new PlaceholderView(c);\n            }\n            if (newView != subView || i >= view.getChildCount()) {\n                if (i < view.getChildCount()) {\n                    view.removeView(subView);\n                }\n                newView.setLayoutParams(mItemLayoutParams);\n                view.addView(newView, i);\n            }\n        }\n\n        return view;\n    }\n\n    @Override\n    public int getItemViewType(int position) {\n        if (mAdapter != null) {\n            return mAdapter.getItemViewType(position);\n        }\n\n        return -1;\n    }\n\n    @Override\n    public int getViewTypeCount() {\n        if (mAdapter != null) {\n            return mAdapter.getViewTypeCount();\n        }\n        return 1;\n    }\n\n    @Override\n    public void registerDataSetObserver(DataSetObserver observer) {\n        if (mAdapter != null) {\n            mAdapter.registerDataSetObserver(observer);\n        }\n    }\n\n    @Override\n    public void unregisterDataSetObserver(DataSetObserver observer) {\n        if (mAdapter != null) {\n            mAdapter.unregisterDataSetObserver(observer);\n        }\n    }\n\n    @Override\n    public ListAdapter getWrappedAdapter() {\n        return mAdapter;\n    }\n\n    public static class PlaceholderView extends View {\n\n        public PlaceholderView(Context context) {\n            super(context);\n        }\n\n    }\n}"
  },
  {
    "path": "src/com/sothree/multiitemrowlistadapter/demo/DemoActivity.java",
    "content": "package com.sothree.multiitemrowlistadapter.demo;\n\nimport com.sothree.multiitemrowlistadapter.MultiItemRowListAdapter;\nimport com.sothree.slidinguppaneldemo.R;\nimport android.net.Uri;\nimport android.os.Build;\nimport android.os.Bundle;\nimport android.provider.ContactsContract;\nimport android.provider.ContactsContract.Contacts;\nimport android.provider.ContactsContract.Contacts.Photo;\nimport android.app.Activity;\nimport android.app.ListActivity;\nimport android.app.LoaderManager;\nimport android.content.Context;\nimport android.content.CursorLoader;\nimport android.content.Loader;\nimport android.database.Cursor;\nimport android.view.LayoutInflater;\nimport android.view.Menu;\nimport android.view.View;\nimport android.view.View.OnClickListener;\nimport android.view.ViewGroup;\nimport android.widget.AdapterView;\nimport android.widget.AdapterView.OnItemClickListener;\nimport android.widget.BaseAdapter;\nimport android.widget.ImageView;\nimport android.widget.TextView;\nimport android.widget.Toast;\n\npublic class DemoActivity extends ListActivity implements\nLoaderManager.LoaderCallbacks<Cursor>,\nOnItemClickListener {\n\n    private ContactsAdapter mContactsAdapter;\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_demo);\n\n        mContactsAdapter = new ContactsAdapter(this);\n        // We need to set the item on click listener on the original adapter instead of the ListView\n        // since each row in MultiItemRowListAdapter has multiple items\n        mContactsAdapter.setOnItemClickListener(this);\n\n        int spacing = (int)getResources().getDimension(R.dimen.spacing);\n        int itemsPerRow = getResources().getInteger(R.integer.items_per_row);\n        MultiItemRowListAdapter wrapperAdapter = new MultiItemRowListAdapter(this, mContactsAdapter, itemsPerRow, spacing);\n        setListAdapter(wrapperAdapter);\n        getLoaderManager().restartLoader(0, null, this);\n    }\n\n    @Override\n    protected void onDestroy() {\n        super.onDestroy();\n        mContactsAdapter.close();\n    }\n\n    @Override\n    public boolean onCreateOptionsMenu(Menu menu) {\n        // Inflate the menu; this adds items to the action bar if it is present.\n        getMenuInflater().inflate(R.menu.demo, menu);\n        return true;\n    }\n\n    @Override\n    public Loader<Cursor> onCreateLoader(int id, Bundle bundle) {\n        Uri uri = ContactsContract.Contacts.CONTENT_URI;\n        String[] projection;\n        String displayNameColumn;\n        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {\n            displayNameColumn = ContactsContract.Contacts.DISPLAY_NAME_PRIMARY;\n            projection= new String[] {\n                ContactsContract.Contacts._ID,\n                ContactsContract.Contacts.PHOTO_THUMBNAIL_URI,\n                displayNameColumn\n            };\n\n        } else {\n            displayNameColumn = ContactsContract.Contacts.DISPLAY_NAME;\n            projection= new String[] {\n                ContactsContract.Contacts._ID,\n                displayNameColumn\n            };\n        }\n        String selection =\n                ContactsContract.Contacts.IN_VISIBLE_GROUP + \" = '1' AND \" +\n                \"NULLIF(\" + displayNameColumn +\", '') IS NOT NULL\";\n        String[] selectionArgs = null;\n        String sortOrder = ContactsContract.Contacts.STARRED + \" DESC, \" + ContactsContract.Contacts.DISPLAY_NAME + \" COLLATE LOCALIZED ASC\";\n        return new CursorLoader(DemoActivity.this, uri, projection, selection, selectionArgs, sortOrder);\n    }\n\n    @Override\n    public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {\n        mContactsAdapter.swapCursor(cursor);\n    }\n\n    @Override\n    public void onLoaderReset(Loader<Cursor> arg0) {\n        mContactsAdapter.swapCursor(null);\n    }\n    private static class ContactsAdapter extends BaseAdapter {\n        private final LayoutInflater mInflater;\n\n        private Cursor mCursor;\n        private OnItemClickListener mOnItemClickListener;\n\n        private final class ContactViewHolder {\n            public TextView mContactName;\n            public ImageView mContactImage;\n        }\n\n        public ContactsAdapter(Activity context) {\n            mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);\n        }\n\n        public void setOnItemClickListener(OnItemClickListener listener) {\n            mOnItemClickListener = listener;\n        }\n\n        public Cursor swapCursor(Cursor newCursor) {\n            if (mCursor != null && mCursor != newCursor) {\n                mCursor.close();\n            }\n            mCursor = newCursor;\n            notifyDataSetChanged();\n            return mCursor;\n        }\n\n        @Override\n        public int getCount() {\n            if (mCursor != null && mCursor.getCount() > 0) {\n                return mCursor.getCount();\n            }\n            return 0;\n        }\n\n        @Override\n        public Object getItem(int position) {\n            if (mCursor != null) {\n                mCursor.moveToPosition(position);\n                return mCursor;\n            }\n            return null;\n        }\n\n        //return the header view, if it's in a section header position\n        @Override\n        public View getView(final int position, View convertView, final ViewGroup parent) {\n            ContactViewHolder viewHolder;\n            if (convertView == null || !(convertView.getTag() instanceof ContactViewHolder)) {\n                convertView = mInflater.inflate(R.layout.include_list_item_contact, parent, false);\n                viewHolder = new ContactViewHolder();\n                viewHolder.mContactName = (TextView) convertView.findViewById(R.id.lbl_contact_name);\n                viewHolder.mContactImage = (ImageView) convertView.findViewById(R.id.image);\n                convertView.setTag(viewHolder);\n            } else {\n                viewHolder = (ContactViewHolder)convertView.getTag();\n            }\n            Cursor c = (Cursor)getItem(position);\n\n            if (c == null) {\n                return convertView;\n            }\n\n            int photoColumnIndex;\n            int nameColumnIndex;\n\n            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {\n                photoColumnIndex = mCursor.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI);\n                nameColumnIndex = mCursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY);\n            } else {\n                photoColumnIndex = mCursor.getColumnIndex(ContactsContract.Contacts._ID);;\n                nameColumnIndex = mCursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);\n            }\n\n            if (nameColumnIndex >= 0) {\n                viewHolder.mContactName.setText(c.getString(nameColumnIndex));\n            }\n\n            if (photoColumnIndex >= 0 && c.getString(photoColumnIndex) != null) {\n                String photoData = c.getString(photoColumnIndex);\n                // Creates a holder for the URI.\n                Uri thumbUri;\n                // If Android 3.0 or later\n                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {\n                    // Sets the URI from the incoming PHOTO_THUMBNAIL_URI\n                    thumbUri = Uri.parse(photoData);\n                } else {\n                    // Prior to Android 3.0, constructs a photo Uri using _ID\n                    /*\n                     * Creates a contact URI from the Contacts content URI\n                     * incoming photoData (_ID)\n                     */\n                    final Uri contactUri = Uri.withAppendedPath(\n                            Contacts.CONTENT_URI, photoData);\n                    /*\n                     * Creates a photo URI by appending the content URI of\n                     * Contacts.Photo.\n                     */\n                    thumbUri =\n                            Uri.withAppendedPath(\n                                    contactUri, Photo.CONTENT_DIRECTORY);\n                }\n                viewHolder.mContactImage.setImageURI(thumbUri);\n            } else {\n                viewHolder.mContactImage.setImageResource(0);\n            }\n\n            final View clickedView = convertView;\n            // set the on click listener for each of the items\n            convertView.setOnClickListener(new OnClickListener() {\n                @Override\n                public void onClick(View v) {\n                    if (mOnItemClickListener != null) {\n                        mOnItemClickListener.onItemClick(null, clickedView, position, position);\n                    }\n\n                }\n            });\n\n            return convertView;\n        }\n\n        @Override\n        public long getItemId(int position) {\n            return position;\n        }\n\n        @Override\n        public boolean areAllItemsEnabled() {\n            return false;\n        }\n\n        @Override\n        public boolean isEnabled(int position) {\n            return true;\n        }\n\n        public void close() {\n            if (mCursor != null) {\n                mCursor.close();\n            }\n        }\n    }\n    @Override\n    public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {\n        if (mContactsAdapter != null) {\n            Cursor c = (Cursor)mContactsAdapter.getItem(position);\n            String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY));\n            Toast t = Toast.makeText(this, \"Clicked \" + name, Toast.LENGTH_SHORT);\n            t.show();\n        }\n    }\n}\n"
  }
]