├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── dictionaries │ └── Giuseppe.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE.md ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── gvillani │ │ └── it │ │ └── pinnedlistdemo │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── gvillani │ │ │ └── it │ │ │ └── pinnedlistdemo │ │ │ ├── Contact.java │ │ │ ├── ContactAdapter.java │ │ │ ├── DemoActivity.java │ │ │ ├── DemoImageActivity.java │ │ │ ├── DemoTextActivity.java │ │ │ └── RoundedImageView.java │ └── res │ │ ├── drawable │ │ ├── contact1.jpg │ │ ├── contact10.jpg │ │ ├── contact11.png │ │ ├── contact2.jpg │ │ ├── contact3.jpg │ │ ├── contact4.jpg │ │ ├── contact5.jpg │ │ ├── contact6.jpg │ │ ├── contact7.jpg │ │ ├── contact8.jpg │ │ ├── contact9.jpg │ │ ├── france.png │ │ ├── germany.png │ │ ├── italy.png │ │ ├── kenya.png │ │ ├── me.jpg │ │ ├── morocco.png │ │ ├── netherlands.png │ │ ├── portugal.png │ │ ├── spain.png │ │ └── sweden.png │ │ ├── layout │ │ ├── activity_image_demo.xml │ │ ├── activity_text_demo.xml │ │ └── item_contact.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── gvillani │ └── it │ └── pinnedlistdemo │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── image_demo1.gif ├── pinnedlist ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── gvillani │ │ └── pinnedlist │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── gvillani │ │ │ └── pinnedlist │ │ │ ├── Group.java │ │ │ ├── GroupListWrapper.java │ │ │ ├── ImageItemPinned.java │ │ │ ├── ItemPinned.java │ │ │ ├── PinBehavior.java │ │ │ ├── PinUtils.java │ │ │ ├── PinnedAdapter.java │ │ │ ├── PinnedListLayout.java │ │ │ ├── PinnedRecyclerView.java │ │ │ ├── PinnedViewHolder.java │ │ │ └── TextItemPinned.java │ └── res │ │ ├── layout │ │ ├── iv_indicator.xml │ │ ├── pin_tv.xml │ │ └── tv_indicator.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── ids.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── gvillani │ └── pinnedlist │ └── ExampleUnitTest.java ├── settings.gradle └── text_demo1.gif /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | PinnedListDemo -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/dictionaries/Giuseppe.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 51 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PinnedRecyclerView Android library 2 | This library allows you to create a list of items that are pinned by a floating label (text or image) on the left of the list . 3 | 4 | ## PinnedRecyclerView in action 5 | 6 | ![Demo Text Pinned](https://github.com/Joseph82/PinnedList-Android/blob/master/text_demo1.gif?raw=true) 7 | 8 | ![Demo Image Pinned](https://github.com/Joseph82/PinnedList-Android/blob/master/image_demo1.gif?raw=true) 9 | 10 | ## Usage 11 | 12 | ### Add library 13 | 14 | #### Gradle 15 | 16 | ```groovy 17 | compile 'com.gvillani:pinnedlist:0.9.2' 18 | ``` 19 | #### Maven 20 | 21 | ```xml 22 | 23 | com.gvillani 24 | pinnedlist 25 | 0.9.2 26 | pom 27 | 28 | ``` 29 | 30 | ### Pinned Text List 31 | 32 | Add the `PinnedListLayout` in your Layout. 33 | 34 | ```xml 35 | 46 | ``` 47 | 48 | Get a reference to the PinnedLayout and get the RecyclerView that it contains. 49 | 50 | ```Java 51 | mListLayout = (PinnedListLayout)findViewById(R.id.pinned_layout); 52 | mRecyclerView = mListLayout.getRecyclerView(); 53 | ``` 54 | 55 | Create a `GroupListWrapper` with the static method `createAlphabeticList()`. You can also create it manually managing each group, but if you want a simple alphabetically ordered list using create `createAlphabeticList()` is the fastest way. 56 | 57 | ```Java 58 | GroupListWrapper listGroup = GroupListWrapper.createAlphabeticList(contacts, GroupListWrapper.ASCENDING); 59 | ``` 60 | 61 | And finally instantiate your custom Adapter (it must extend `PinnedAdapter`) and set it to the RecyclerView 62 | 63 | ```Java 64 | mListAdapter = new ContactAdapter(this, listGroup, mListLayout); 65 | mRecyclerView.setAdapter(mListAdapter); 66 | ``` 67 | 68 | Moreover, if you want create a GroupListWrapper using the `createAlphabeticList` you need to tell the system which label will be applied for your object and the related order. For example if you have a Contact object that contains name and surname you can do something like this: 69 | 70 | ```Java 71 | public class Contact implements GroupListWrapper.Selector{ 72 | private String name; 73 | private String surname; 74 | 75 | @Override 76 | public String select() { 77 | return name+surname; 78 | } 79 | } 80 | ``` 81 | 82 | In this way you are telling the system that you want that your pin label will have the first letter of the name and they should be ordered using the name and the surname (if the name is the same). 83 | 84 | ### Pinned Image List 85 | 86 | In order to use a pinned list with image you need to set in your layout: 87 | 88 | `app:type="image"` 89 | 90 | You create your `GroupListWrapper` 91 | 92 | ```Java 93 | GroupListWrapper listGroup = new GroupListWrapper(); 94 | ``` 95 | 96 | Then you need to create a list of wrapping object (ItemPinned) that contain your costom object (for example a Contact) and then you add 97 | 98 | ```Java 99 | ItemPinned itemD1 = new ImageItemPinned(new Contact("Ben","Weber", R.drawable.contact1)); 100 | ItemPinned itemD2 = new ImageItemPinned(new Contact("Emma","Hartmann", R.drawable.contact9)); 101 | 102 | List listD = new ArrayList<>(); 103 | listD.add(itemD1); 104 | listD.add(itemD2); 105 | 106 | Group groupD = new Group(listD, R.drawable.germany); 107 | ``` 108 | 109 | And eventually you add one or more `Group` object to the `GroupListWrapper` 110 | 111 | ```Java 112 | listGroup.addGroup(groupD); 113 | ``` 114 | 115 | Finally instantiate your custom Adapter (it must extend `PinnedAdapter`) and set it to the RecyclerView 116 | 117 | ```Java 118 | mListAdapter = new ContactAdapter(this, listGroup, mListLayout); 119 | mRecyclerView.setAdapter(mListAdapter); 120 | ``` 121 | 122 | ### The Adapter 123 | 124 | As before mentioned, you need to create your custom Adapter extending `PinnedAdapter` class. 125 | 126 | When you override the method `onCreateViewHolder` you need to create your custom row layout (for example using inflater) and then you need to allow the system to wrap that layout inside a layout that contains the pin. So, you simply need to obtain a wrapped version of your layout passing it to `getRowLayout()` as shown in the example below: 127 | 128 | ```Java 129 | @Override 130 | public PinnedViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 131 | View view = mLayoutInflater.inflate(R.layout.item_contact, parent, false); 132 | ViewHolderContact viewHolderContact = new ViewHolderContact(getRowLayout(view)); 133 | return viewHolderContact; 134 | } 135 | ``` 136 | 137 | ## Note 138 | 139 | Currently the Library is created as a compound View wrapped inside a CoordinatorLayout. So, if you need to use a CoordinatorLayout you can use it: for example you can add a Toolbar inside it, or a FAB that will be automatically coordinated with the Snackbar. 140 | 141 | The library support only the LinearLayoutManager, so if you try to set a different layout it will be ignored. 142 | 143 | ## TODO 144 | 145 | * Allow the user to manipulate the content of the adapter without replacing the entire dataset. 146 | * Support for `GridLayoutManager` 147 | * Find different strategy that make the wrapping of the custom layout inside the pinner layout more transparent (user should not call `getRowLayout()` from his adapter) 148 | * Allow groups manipulation 149 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | applicationId "gvillani.it.pinnedlistdemo" 9 | minSdkVersion 16 10 | targetSdkVersion 24 11 | versionCode 2 12 | versionName "1.1" 13 | } 14 | 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | compile fileTree(dir: 'libs', include: ['*.jar']) 25 | testCompile 'junit:junit:4.12' 26 | compile 'com.android.support:appcompat-v7:24.2.0' 27 | compile project(':pinnedlist') 28 | } 29 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\Giuseppe\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/gvillani/it/pinnedlistdemo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package gvillani.it.pinnedlistdemo; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/java/gvillani/it/pinnedlistdemo/Contact.java: -------------------------------------------------------------------------------- 1 | package gvillani.it.pinnedlistdemo; 2 | 3 | import com.gvillani.pinnedlist.GroupListWrapper; 4 | 5 | /** 6 | * Created by Giuseppe on 09/04/2016. 7 | */ 8 | public class Contact implements GroupListWrapper.Selector{ 9 | private String name; 10 | private String surname; 11 | private Integer photo; 12 | 13 | public Contact(String name, String surname, Integer photo) { 14 | this.name = name; 15 | this.surname = surname; 16 | this.photo = photo; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setName(String name) { 24 | this.name = name; 25 | } 26 | 27 | public Integer getPhoto() { 28 | return photo; 29 | } 30 | 31 | public void setPhoto(Integer photo) { 32 | this.photo = photo; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return "Contact{" + 38 | "name='" + name + '\'' + 39 | ", surname='" + surname + '\'' + 40 | ", photo=" + photo + 41 | '}'; 42 | } 43 | 44 | @Override 45 | public String select() { 46 | return getName()+getSurname(); 47 | } 48 | 49 | public String getSurname() { 50 | return surname; 51 | } 52 | 53 | public void setSurname(String surname) { 54 | this.surname = surname; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/gvillani/it/pinnedlistdemo/ContactAdapter.java: -------------------------------------------------------------------------------- 1 | package gvillani.it.pinnedlistdemo; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.TextView; 9 | 10 | import com.gvillani.pinnedlist.GroupListWrapper; 11 | import com.gvillani.pinnedlist.PinnedAdapter; 12 | import com.gvillani.pinnedlist.PinnedListLayout; 13 | import com.gvillani.pinnedlist.PinnedViewHolder; 14 | 15 | /** 16 | * Created by Giuseppe on 09/04/2016. 17 | */ 18 | public class ContactAdapter extends PinnedAdapter { 19 | private final LayoutInflater mLayoutInflater; 20 | 21 | public ContactAdapter(Context context, GroupListWrapper listGroup, PinnedListLayout layout) { 22 | super(listGroup, layout); 23 | mLayoutInflater = LayoutInflater.from(context); 24 | } 25 | 26 | @Override 27 | public PinnedViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 28 | View view = mLayoutInflater.inflate(R.layout.item_contact, parent, false); 29 | PinnedViewHolder pinnedViewHolder = new ViewHolderContact(getRowLayout(view)); 30 | return pinnedViewHolder; 31 | } 32 | 33 | @Override 34 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 35 | super.onBindViewHolder(holder, position); 36 | 37 | final Contact contact = (Contact) mListWrapper.getItem(position); 38 | 39 | ((ViewHolderContact) holder).tvName.setText(contact.getName()); 40 | ((ViewHolderContact) holder).tvSurname.setText(contact.getSurname()); 41 | ((ViewHolderContact) holder).ivPhoto.setImageResource(contact.getPhoto()); 42 | } 43 | 44 | static class ViewHolderContact extends PinnedViewHolder { 45 | private RoundedImageView ivPhoto; 46 | private TextView tvName; 47 | private TextView tvSurname; 48 | 49 | public ViewHolderContact(View rowLayout) { 50 | super(rowLayout); 51 | ivPhoto = (RoundedImageView) rowLayout.findViewById(R.id.photo); 52 | tvName = (TextView) rowLayout.findViewById(R.id.name); 53 | tvSurname = (TextView) rowLayout.findViewById(R.id.surname); 54 | } 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /app/src/main/java/gvillani/it/pinnedlistdemo/DemoActivity.java: -------------------------------------------------------------------------------- 1 | package gvillani.it.pinnedlistdemo; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | import android.widget.AdapterView; 8 | import android.widget.ArrayAdapter; 9 | import android.widget.ListView; 10 | 11 | /** 12 | * Created by Giuseppe on 09/04/2016. 13 | */ 14 | public class DemoActivity extends AppCompatActivity implements AdapterView.OnItemClickListener{ 15 | 16 | private String[] mItems; 17 | private Intent[] mActions; 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | 23 | ListView list = new ListView(this); 24 | setContentView(list); 25 | 26 | buildActionsList(); 27 | 28 | ArrayAdapter adapter = new ArrayAdapter<>(this, 29 | android.R.layout.simple_list_item_1, mItems); 30 | list.setAdapter(adapter); 31 | list.setOnItemClickListener(this); 32 | 33 | } 34 | 35 | private void buildActionsList() { 36 | mItems = new String[] { 37 | "Text Pinned List", 38 | "Image Pinned List" 39 | }; 40 | 41 | mActions = new Intent[] { 42 | new Intent(this, DemoTextActivity.class), 43 | new Intent(this, DemoImageActivity.class) 44 | }; 45 | } 46 | 47 | @Override 48 | public void onItemClick(AdapterView parent, View view, int position, long id) { 49 | Intent action = mActions[position]; 50 | startActivity(action); 51 | } 52 | } -------------------------------------------------------------------------------- /app/src/main/java/gvillani/it/pinnedlistdemo/DemoImageActivity.java: -------------------------------------------------------------------------------- 1 | package gvillani.it.pinnedlistdemo; 2 | 3 | import android.os.Bundle; 4 | import android.support.design.widget.Snackbar; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.support.v7.widget.Toolbar; 8 | import android.view.View; 9 | 10 | import com.gvillani.pinnedlist.Group; 11 | import com.gvillani.pinnedlist.GroupListWrapper; 12 | import com.gvillani.pinnedlist.ImageItemPinned; 13 | import com.gvillani.pinnedlist.ItemPinned; 14 | import com.gvillani.pinnedlist.PinnedAdapter; 15 | import com.gvillani.pinnedlist.PinnedListLayout; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | /** 21 | * Created by Giuseppe on 19/04/2016. 22 | */ 23 | public class DemoImageActivity extends AppCompatActivity { 24 | 25 | private PinnedListLayout mListLayout; 26 | private PinnedAdapter mListAdapter; 27 | private RecyclerView mRecyclerView; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_image_demo); 33 | 34 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 35 | setSupportActionBar(toolbar); 36 | 37 | initLayout(); 38 | 39 | findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() { 40 | @Override 41 | public void onClick(View view) { 42 | Snackbar.make(view, "CoordinatorLayout still works! :)", Snackbar.LENGTH_LONG).show(); 43 | } 44 | }); 45 | } 46 | 47 | 48 | private void initLayout() { 49 | mListLayout = (PinnedListLayout) findViewById(R.id.pinned_layout); 50 | mRecyclerView = mListLayout.getRecyclerView(); 51 | 52 | GroupListWrapper listGroup = createItems(); 53 | 54 | mListAdapter = new ContactAdapter(this, listGroup, mListLayout); 55 | mRecyclerView.setAdapter(mListAdapter); 56 | 57 | } 58 | 59 | private GroupListWrapper createItems() { 60 | GroupListWrapper listGroup = new GroupListWrapper(); 61 | 62 | ItemPinned itemD1 = new ImageItemPinned(new Contact("Ben", "Weber", R.drawable.contact1)); // M 63 | ItemPinned itemD2 = new ImageItemPinned(new Contact("Emma", "Hartmann", R.drawable.contact9)); //F 64 | 65 | List listD = new ArrayList(); 66 | listD.add(itemD1); 67 | listD.add(itemD2); 68 | Group groupD = new Group(listD, R.drawable.germany); 69 | 70 | 71 | ItemPinned itemS1 = new ImageItemPinned(new Contact("Gustav", "Eriksson", R.drawable.contact7)); //M 72 | ItemPinned itemS2 = new ImageItemPinned(new Contact("Lucas", "Nillson", R.drawable.contact4)); //M 73 | ItemPinned itemS3 = new ImageItemPinned(new Contact("Maia", "Andersson", R.drawable.contact11)); //F 74 | ItemPinned itemS4 = new ImageItemPinned(new Contact("Oscar", "Karlsson", R.drawable.contact6)); //M 75 | ItemPinned itemS5 = new ImageItemPinned(new Contact("Williams", "Johansson", R.drawable.contact5)); //M 76 | 77 | List listS = new ArrayList(); 78 | listS.add(itemS1); 79 | listS.add(itemS2); 80 | listS.add(itemS3); 81 | listS.add(itemS4); 82 | listS.add(itemS5); 83 | Group groupS = new Group(listS, R.drawable.sweden); 84 | 85 | 86 | ItemPinned itemNL1 = new ImageItemPinned(new Contact("Jayden", "De Jong", R.drawable.contact4)); //M 87 | ItemPinned itemNL2 = new ImageItemPinned(new Contact("Julia", "Meijer", R.drawable.contact11)); // F 88 | ItemPinned itemNL3 = new ImageItemPinned(new Contact("Lieke", "Visser", R.drawable.contact2)); //F 89 | ItemPinned itemNL4 = new ImageItemPinned(new Contact("Luuk", "Tassi", R.drawable.contact3)); //M 90 | ItemPinned itemNL5 = new ImageItemPinned(new Contact("Sam", "Van den Berg", R.drawable.contact1)); //M 91 | ItemPinned itemNL6 = new ImageItemPinned(new Contact("Stijn", "De Vries", R.drawable.contact6)); //M 92 | ItemPinned itemNL7 = new ImageItemPinned(new Contact("Thomas", "Van Dijk", R.drawable.contact5)); //M 93 | 94 | 95 | List listNL = new ArrayList(); 96 | listNL.add(itemNL1); 97 | listNL.add(itemNL2); 98 | listNL.add(itemNL3); 99 | listNL.add(itemNL4); 100 | listNL.add(itemNL5); 101 | listNL.add(itemNL6); 102 | listNL.add(itemNL7); 103 | Group groupNL = new Group(listNL, R.drawable.netherlands); 104 | 105 | 106 | ItemPinned itemIT1 = new ImageItemPinned(new Contact("Franco", "Bianchi", R.drawable.contact3)); //F 107 | ItemPinned itemIT2 = new ImageItemPinned(new Contact("Giuseppe", "Villani", R.drawable.me)); // M 108 | ItemPinned itemIT3 = new ImageItemPinned(new Contact("Lisa", "Verdi", R.drawable.contact9)); //F 109 | ItemPinned itemIT4 = new ImageItemPinned(new Contact("Maria", "Rossi", R.drawable.contact10)); //M 110 | 111 | 112 | List listIT = new ArrayList(); 113 | listIT.add(itemIT1); 114 | listIT.add(itemIT2); 115 | listIT.add(itemIT3); 116 | listIT.add(itemIT4); 117 | Group groupIT = new Group(listIT, R.drawable.italy); 118 | 119 | 120 | ItemPinned itemP1 = new ImageItemPinned(new Contact("Leonor", "Santos", R.drawable.contact9)); //F 121 | ItemPinned itemP2 = new ImageItemPinned(new Contact("Santiago", "Ferreira", R.drawable.contact1)); // M 122 | ItemPinned itemP3 = new ImageItemPinned(new Contact("Maria", "Pereira", R.drawable.contact9)); //F 123 | ItemPinned itemP4 = new ImageItemPinned(new Contact("Francisco", "Sousa", R.drawable.contact4)); //M 124 | ItemPinned itemP5 = new ImageItemPinned(new Contact("Rodrigo", "Martins", R.drawable.contact5)); //M 125 | ItemPinned itemP6 = new ImageItemPinned(new Contact("Duarte", "Gomes", R.drawable.contact6)); //M 126 | 127 | List listP = new ArrayList(); 128 | listP.add(itemP1); 129 | listP.add(itemP2); 130 | listP.add(itemP3); 131 | listP.add(itemP4); 132 | listP.add(itemP5); 133 | listP.add(itemP6); 134 | Group groupP = new Group(listP, R.drawable.portugal); 135 | 136 | 137 | ItemPinned itemES1 = new ImageItemPinned(new Contact("Lucia", "Garcia", R.drawable.contact9)); //F 138 | ItemPinned itemES2 = new ImageItemPinned(new Contact("Pedro", "Fernandez", R.drawable.contact1)); // M 139 | ItemPinned itemES3 = new ImageItemPinned(new Contact("Daniela", "Gonzales", R.drawable.contact9)); //F 140 | ItemPinned itemES4 = new ImageItemPinned(new Contact("Alvaro", "Perez", R.drawable.contact7)); //M 141 | ItemPinned itemES5 = new ImageItemPinned(new Contact("David", "Martin", R.drawable.contact3)); //M 142 | 143 | List listES = new ArrayList(); 144 | listES.add(itemES1); 145 | listES.add(itemES2); 146 | listES.add(itemES3); 147 | listES.add(itemES4); 148 | listES.add(itemES5); 149 | Group groupES = new Group(listES, R.drawable.spain); 150 | 151 | 152 | ItemPinned itemF1 = new ImageItemPinned(new Contact("Camille", "Bernard", R.drawable.contact9)); //F 153 | ItemPinned itemF2 = new ImageItemPinned(new Contact("Louis", "Robert", R.drawable.contact1)); // M 154 | ItemPinned itemF3 = new ImageItemPinned(new Contact("Jules", "Petit", R.drawable.contact4)); //M 155 | 156 | List listF = new ArrayList(); 157 | listF.add(itemF1); 158 | listF.add(itemF2); 159 | listF.add(itemF3); 160 | Group groupF = new Group(listF, R.drawable.france); 161 | 162 | 163 | ItemPinned itemEAK1 = new ImageItemPinned(new Contact("Daniel", "Kimani", R.drawable.contact8)); //M 164 | ItemPinned itemEAK2 = new ImageItemPinned(new Contact("Faith", "Mwangi", R.drawable.contact9)); //F 165 | ItemPinned itemEAK3 = new ImageItemPinned(new Contact("Jamesohn", "Kamau", R.drawable.contact1)); // M 166 | ItemPinned itemEAK4 = new ImageItemPinned(new Contact("Jonson", "Kariuki", R.drawable.contact3)); //M 167 | ItemPinned itemEAK5 = new ImageItemPinned(new Contact("Victor", "Ochieng", R.drawable.contact6)); //M 168 | 169 | List listEAK = new ArrayList(); 170 | listEAK.add(itemEAK1); 171 | listEAK.add(itemEAK2); 172 | listEAK.add(itemEAK3); 173 | listEAK.add(itemEAK4); 174 | listEAK.add(itemEAK5); 175 | Group groupEAK = new Group(listEAK, R.drawable.kenya); 176 | 177 | 178 | ItemPinned itemMA1 = new ImageItemPinned(new Contact("Aziza", "Elzarak", R.drawable.contact9)); //F 179 | ItemPinned itemMA2 = new ImageItemPinned(new Contact("Youssef", "Jamil", R.drawable.contact1)); // M 180 | 181 | List listMA = new ArrayList(); 182 | listMA.add(itemMA1); 183 | listMA.add(itemMA2); 184 | Group groupMA = new Group(listMA, R.drawable.morocco); 185 | 186 | 187 | listGroup.addGroup(groupD); 188 | listGroup.addGroup(groupS); 189 | listGroup.addGroup(groupNL); 190 | listGroup.addGroup(groupIT); 191 | listGroup.addGroup(groupP); 192 | listGroup.addGroup(groupES); 193 | listGroup.addGroup(groupF); 194 | listGroup.addGroup(groupEAK); 195 | listGroup.addGroup(groupMA); 196 | 197 | return listGroup; 198 | } 199 | 200 | } 201 | -------------------------------------------------------------------------------- /app/src/main/java/gvillani/it/pinnedlistdemo/DemoTextActivity.java: -------------------------------------------------------------------------------- 1 | package gvillani.it.pinnedlistdemo; 2 | 3 | import android.os.Bundle; 4 | import android.support.design.widget.Snackbar; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.support.v7.widget.Toolbar; 8 | import android.view.View; 9 | 10 | import com.gvillani.pinnedlist.GroupListWrapper; 11 | import com.gvillani.pinnedlist.PinnedListLayout; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | /** 17 | * Created by Giuseppe on 19/04/2016. 18 | */ 19 | public class DemoTextActivity extends AppCompatActivity { 20 | 21 | private PinnedListLayout mPinnedListLayout; 22 | private RecyclerView.Adapter mListAdapter; 23 | private RecyclerView mRecyclerView; 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.activity_text_demo); 29 | 30 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 31 | setSupportActionBar(toolbar); 32 | 33 | initLayout(); 34 | 35 | 36 | findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() { 37 | @Override 38 | public void onClick(View view) { 39 | Snackbar.make(view, "CoordinatorLayout still works! :)", Snackbar.LENGTH_LONG).show(); 40 | } 41 | }); 42 | } 43 | 44 | private void initLayout() { 45 | mPinnedListLayout = (PinnedListLayout) findViewById(R.id.pinned_layout); 46 | mRecyclerView = mPinnedListLayout.getRecyclerView(); 47 | 48 | Contact c1 = new Contact("Ben", "Weber", R.drawable.contact1); 49 | Contact c2 = new Contact("Emma", "Hartmann", R.drawable.contact9); 50 | Contact c3 = new Contact("Gustav", "Eriksson", R.drawable.contact7); 51 | Contact c4 = new Contact("Lucas", "Nillson", R.drawable.contact4); 52 | Contact c5 = new Contact("Maia", "Andersson", R.drawable.contact11); 53 | Contact c6 = new Contact("Oscar", "Karlsson", R.drawable.contact6); 54 | Contact c7 = new Contact("Williams", "Johansson", R.drawable.contact5); 55 | Contact c8 = new Contact("Jayden", "De Jong", R.drawable.contact4); 56 | Contact c9 = new Contact("Julia", "Meijer", R.drawable.contact11); 57 | Contact c10 = new Contact("Lieke", "Visser", R.drawable.contact2); 58 | Contact c11 = new Contact("Luuk", "Tassi", R.drawable.contact3); 59 | Contact c12 = new Contact("Sam", "Van den Berg", R.drawable.contact1); 60 | Contact c13 = new Contact("Stijn", "De Vries", R.drawable.contact6); 61 | Contact c14 = new Contact("Thomas", "Van Dijk", R.drawable.contact5); 62 | Contact c15 = new Contact("Franco", "Bianchi", R.drawable.contact3); 63 | Contact c16 = new Contact("Giuseppe", "Villani", R.drawable.me); 64 | Contact c17 = new Contact("Lisa", "Verdi", R.drawable.contact9); 65 | Contact c18 = new Contact("Maria", "Rossi", R.drawable.contact10); 66 | Contact c19 = new Contact("Leonor", "Santos", R.drawable.contact9); 67 | Contact c20 = new Contact("Santiago", "Ferreira", R.drawable.contact1); 68 | Contact c21 = new Contact("Maria", "Pereira", R.drawable.contact9); 69 | Contact c22 = new Contact("Francisco", "Sousa", R.drawable.contact4); 70 | Contact c23 = new Contact("Rodrigo", "Martins", R.drawable.contact5); 71 | Contact c24 = new Contact("Duarte", "Gomes", R.drawable.contact6); 72 | Contact c25 = new Contact("Lucia", "Garcia", R.drawable.contact9); 73 | Contact c26 = new Contact("Pedro", "Fernandez", R.drawable.contact1); 74 | Contact c27 = new Contact("Daniela", "Gonzales", R.drawable.contact9); 75 | Contact c28 = new Contact("Alvaro", "Perez", R.drawable.contact7); 76 | Contact c29 = new Contact("David", "Martin", R.drawable.contact3); 77 | Contact c30 = new Contact("Camille", "Bernard", R.drawable.contact9); 78 | Contact c31 = new Contact("Louis", "Robert", R.drawable.contact1); 79 | Contact c32 = new Contact("Jules", "Petit", R.drawable.contact4); 80 | Contact c33 = new Contact("Daniel", "Kimani", R.drawable.contact8); 81 | Contact c34 = new Contact("Faith", "Mwangi", R.drawable.contact9); 82 | Contact c35 = new Contact("Jamesohn", "Kamau", R.drawable.contact1); 83 | Contact c36 = new Contact("Jonson", "Kariuki", R.drawable.contact3); 84 | Contact c37 = new Contact("Victor", "Ochieng", R.drawable.contact6); 85 | Contact c38 = new Contact("Aziza", "Elzarak", R.drawable.contact9); 86 | Contact c39 = new Contact("Youssef", "Jamil", R.drawable.contact1); 87 | Contact c40 = new Contact("Bob", "Miller", R.drawable.contact4); 88 | Contact c41 = new Contact("Carl", "Mayer", R.drawable.contact6); 89 | Contact c42 = new Contact("Bill", "Carson", R.drawable.contact5); 90 | Contact c43 = new Contact("Thom", "Sayer", R.drawable.contact1); 91 | Contact c44 = new Contact("Jim", "Hall", R.drawable.contact6); 92 | Contact c45 = new Contact("Paul", "Stroustrup", R.drawable.contact3); 93 | 94 | List contacts = new ArrayList<>(); 95 | 96 | contacts.add(c1); 97 | contacts.add(c2); 98 | contacts.add(c3); 99 | contacts.add(c4); 100 | contacts.add(c5); 101 | contacts.add(c6); 102 | contacts.add(c7); 103 | contacts.add(c8); 104 | contacts.add(c9); 105 | contacts.add(c10); 106 | contacts.add(c11); 107 | contacts.add(c12); 108 | contacts.add(c13); 109 | contacts.add(c14); 110 | contacts.add(c15); 111 | contacts.add(c16); 112 | contacts.add(c17); 113 | contacts.add(c18); 114 | contacts.add(c19); 115 | contacts.add(c20); 116 | contacts.add(c21); 117 | contacts.add(c22); 118 | contacts.add(c23); 119 | contacts.add(c24); 120 | contacts.add(c25); 121 | contacts.add(c26); 122 | contacts.add(c27); 123 | contacts.add(c28); 124 | contacts.add(c29); 125 | contacts.add(c30); 126 | contacts.add(c31); 127 | contacts.add(c32); 128 | contacts.add(c33); 129 | contacts.add(c34); 130 | contacts.add(c35); 131 | contacts.add(c36); 132 | contacts.add(c37); 133 | contacts.add(c38); 134 | contacts.add(c39); 135 | contacts.add(c40); 136 | contacts.add(c41); 137 | contacts.add(c42); 138 | contacts.add(c43); 139 | contacts.add(c44); 140 | contacts.add(c45); 141 | 142 | GroupListWrapper listGroup = GroupListWrapper.createAlphabeticList(contacts, GroupListWrapper.ASCENDING); 143 | 144 | mListAdapter = new ContactAdapter(this, listGroup, mPinnedListLayout); 145 | mRecyclerView.setAdapter(mListAdapter); 146 | } 147 | } -------------------------------------------------------------------------------- /app/src/main/java/gvillani/it/pinnedlistdemo/RoundedImageView.java: -------------------------------------------------------------------------------- 1 | package gvillani.it.pinnedlistdemo; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.Canvas; 6 | import android.graphics.Color; 7 | import android.graphics.Paint; 8 | import android.graphics.PorterDuff; 9 | import android.graphics.PorterDuffXfermode; 10 | import android.graphics.Rect; 11 | import android.graphics.drawable.BitmapDrawable; 12 | import android.graphics.drawable.Drawable; 13 | import android.util.AttributeSet; 14 | import android.widget.ImageView; 15 | 16 | /** 17 | * Created by Giuseppe on 09/04/2016. 18 | */ 19 | public class RoundedImageView extends ImageView { 20 | 21 | public RoundedImageView(Context context) { 22 | super(context); 23 | } 24 | 25 | public RoundedImageView(Context context, AttributeSet attrs) { 26 | super(context, attrs); 27 | } 28 | 29 | public RoundedImageView(Context context, AttributeSet attrs, int defStyle) { 30 | super(context, attrs, defStyle); 31 | } 32 | 33 | @Override 34 | protected void onDraw(Canvas canvas) { 35 | 36 | Drawable drawable = getDrawable(); 37 | 38 | if (drawable == null) { 39 | return; 40 | } 41 | 42 | if (getWidth() == 0 || getHeight() == 0) { 43 | return; 44 | } 45 | Bitmap b = ((BitmapDrawable) drawable).getBitmap(); 46 | Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true); 47 | 48 | int w = getWidth(), h = getHeight(); 49 | 50 | Bitmap roundBitmap = getCroppedBitmap(bitmap, w); 51 | canvas.drawBitmap(roundBitmap, 0, 0, null); 52 | 53 | } 54 | 55 | public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) { 56 | Bitmap sbmp; 57 | 58 | if (bmp.getWidth() != radius || bmp.getHeight() != radius) { 59 | float smallest = Math.min(bmp.getWidth(), bmp.getHeight()); 60 | float factor = smallest / radius; 61 | sbmp = Bitmap.createScaledBitmap(bmp, (int) (bmp.getWidth() / factor), (int) (bmp.getHeight() / factor), false); 62 | } else { 63 | sbmp = bmp; 64 | } 65 | 66 | Bitmap output = Bitmap.createBitmap(radius, radius, 67 | Bitmap.Config.ARGB_8888); 68 | Canvas canvas = new Canvas(output); 69 | 70 | final int color = 0xffa19774; 71 | final Paint paint = new Paint(); 72 | final Rect rect = new Rect(0, 0, radius, radius); 73 | 74 | paint.setAntiAlias(true); 75 | paint.setFilterBitmap(true); 76 | paint.setDither(true); 77 | canvas.drawARGB(0, 0, 0, 0); 78 | paint.setColor(Color.parseColor("#BAB399")); 79 | canvas.drawCircle(radius / 2 + 0.7f, 80 | radius / 2 + 0.7f, radius / 2 + 0.1f, paint); 81 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); 82 | canvas.drawBitmap(sbmp, rect, rect, paint); 83 | 84 | return output; 85 | } 86 | 87 | } 88 | 89 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/contact1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/contact1.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/contact10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/contact10.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/contact11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/contact11.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/contact2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/contact2.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/contact3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/contact3.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/contact4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/contact4.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/contact5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/contact5.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/contact6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/contact6.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/contact7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/contact7.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/contact8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/contact8.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/contact9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/contact9.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/france.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/france.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/germany.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/germany.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/italy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/italy.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/kenya.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/kenya.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/me.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/me.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/morocco.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/morocco.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/netherlands.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/netherlands.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/portugal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/portugal.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/spain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/spain.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/sweden.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/drawable/sweden.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_image_demo.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 16 | 17 | 24 | 25 | 26 | 27 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_text_demo.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 18 | 19 | 26 | 27 | 28 | 29 | 30 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_contact.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 11 | 19 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | PinnedListDemo 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 | 10 | 11 | -------------------------------------------------------------------------------- /pinnedlist/src/test/java/com/gvillani/pinnedlist/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.gvillani.pinnedlist; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':pinnedlist' 2 | -------------------------------------------------------------------------------- /text_demo1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/text_demo1.gif --------------------------------------------------------------------------------