├── .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 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
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 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
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 |
5 |
6 |
7 |
8 |
9 |
10 |
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 | 
7 |
8 | 
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 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/test/java/gvillani/it/pinnedlistdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package gvillani.it.pinnedlistdemo;
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 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.2'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/image_demo1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Joseph82/PinnedRecyclerView-Android/e7c13a0b5542ce5cde7e52d0c4882f3db9f7a349/image_demo1.gif
--------------------------------------------------------------------------------
/pinnedlist/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/pinnedlist/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 24
10 | versionCode 2
11 | versionName "0.9.2"
12 | }
13 |
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:recyclerview-v7:24.2.0'
26 | compile 'com.android.support:design:24.2.0'
27 | }
28 |
--------------------------------------------------------------------------------
/pinnedlist/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 |
--------------------------------------------------------------------------------
/pinnedlist/src/androidTest/java/com/gvillani/pinnedlist/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.gvillani.pinnedlist;
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 | }
--------------------------------------------------------------------------------
/pinnedlist/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/pinnedlist/src/main/java/com/gvillani/pinnedlist/Group.java:
--------------------------------------------------------------------------------
1 | package com.gvillani.pinnedlist;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * This class wraps the list of items united by the same String label or image
7 | */
8 | public class Group {
9 | protected List items;
10 |
11 | /**
12 | * Creates a Group using a label for grouping items
13 | *
14 | * @param items the list of items
15 | * @param label the String that rapresent the label to be shown
16 | */
17 | public Group(List items, String label) {
18 | this.items = items;
19 | if (this.items != null) {
20 | for (int i = 0; i < this.items.size(); i++) {
21 | ItemPinned itemPinned = this.items.get(i);
22 | initItemPosition(itemPinned, i);
23 | if (this.items.get(i) instanceof TextItemPinned)
24 | ((TextItemPinned) this.items.get(i)).setLabel(label);
25 | }
26 | }
27 | }
28 |
29 | private void initItemPosition(ItemPinned item, int position) {
30 | item.setGroupSize(getGroupSize());
31 | item.setRelativePosition(position);
32 | }
33 |
34 | /**
35 | * Creates a Group using an image for grouping items
36 | *
37 | * @param items the list of items
38 | * @param resourceId resource id associated with the image.
39 | */
40 | public Group(List items, int resourceId) {
41 | this.items = items;
42 | if (this.items != null) {
43 | for (int i = 0; i < this.items.size(); i++) {
44 | ItemPinned itemPinned = this.items.get(i);
45 | initItemPosition(itemPinned, i);
46 | if (this.items.get(i) instanceof ImageItemPinned)
47 | ((ImageItemPinned) this.items.get(i)).setImage(resourceId);
48 | }
49 | }
50 | }
51 |
52 | private int getGroupSize() {
53 | if (this.items != null) {
54 | return this.items.size();
55 | }
56 |
57 | return 0;
58 | }
59 |
60 | public List getItems() {
61 | return items;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/pinnedlist/src/main/java/com/gvillani/pinnedlist/GroupListWrapper.java:
--------------------------------------------------------------------------------
1 | package com.gvillani.pinnedlist;
2 |
3 | import android.support.annotation.IntDef;
4 |
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.text.Collator;
8 | import java.util.ArrayList;
9 | import java.util.Collections;
10 | import java.util.Comparator;
11 | import java.util.HashMap;
12 | import java.util.List;
13 | import java.util.Locale;
14 | import java.util.SortedSet;
15 | import java.util.TreeSet;
16 |
17 | /**
18 | * Class that wraps all the items that have to be mapped in the adapter
19 | */
20 | public class GroupListWrapper {
21 |
22 | @Retention(RetentionPolicy.SOURCE)
23 | @IntDef({ASCENDING, DESCENDING})
24 | public @interface ItemOrder {
25 | }
26 |
27 | public static final int ASCENDING = 0;
28 | public static final int DESCENDING = 1;
29 |
30 | List mItems;
31 |
32 | public GroupListWrapper() {
33 | mItems = new ArrayList<>();
34 | }
35 |
36 | /**
37 | * Adds a new group to the wrapper
38 | *
39 | * @param group the {@link Group} that has to be added
40 | */
41 | public void addGroup(Group group) {
42 | if (group != null && group.getItems() != null) {
43 | mItems.addAll(group.getItems());
44 | }
45 | }
46 |
47 | /**
48 | * Returns the {@link ItemPinned} based on the position paramter
49 | *
50 | * @param position the position inside the list
51 | * @return the {@link ItemPinned} at position parameter or null
52 | */
53 | public ItemPinned getItemPinned(int position) {
54 | if (mItems != null) {
55 | try {
56 | return mItems.get(position);
57 | } catch (IndexOutOfBoundsException indexOutOfBoundsException) {
58 | throw indexOutOfBoundsException;
59 | }
60 |
61 | } else {
62 | return null;
63 | }
64 | }
65 |
66 | /**
67 | * Returns the Object inside the wrapper from the list
68 | *
69 | * @param position the position inside the list
70 | * @return the {@link Object} at position parameter or null
71 | */
72 | public Object getItem(int position) {
73 | if (mItems != null) {
74 | return getItemPinned(position).getItem();
75 | } else {
76 | return null;
77 | }
78 | }
79 |
80 | public int size() {
81 | if (mItems != null)
82 | return mItems.size();
83 | else
84 | return 0;
85 | }
86 |
87 | /**
88 | * Returns a {@link GroupListWrapper} that wraps a list of item, ordered in ASCENDING mode
89 | * @param items the items to be ordered
90 | * @return a {@link GroupListWrapper} object
91 | */
92 | public static GroupListWrapper createAlphabeticList(List items) {
93 | return createAlphabeticList(items, ASCENDING);
94 | }
95 |
96 | /**
97 | * Returns a {@link GroupListWrapper} that wraps an ordered list of items
98 | *
99 | * @param items the items to be ordered
100 | * @param order the ordering mode: DISCENDING or ASCENDING
101 | * @return a {@link GroupListWrapper} object
102 | */
103 | public static GroupListWrapper createAlphabeticList(List items, @ItemOrder int order) {
104 | Collections.sort(items, new CompareItem());
105 |
106 | if (order == DESCENDING) {
107 | Collections.reverse(items);
108 | }
109 |
110 | HashMap> hashMap = new HashMap<>();
111 |
112 | for (Selector item : items) {
113 | if (!hashMap.containsKey(item.select().substring(0, 1).toUpperCase())) {
114 | List list = new ArrayList<>();
115 | list.add(new TextItemPinned(item));
116 |
117 | hashMap.put(item.select().substring(0, 1).toUpperCase(), list);
118 | } else {
119 | hashMap.get(item.select().substring(0, 1).toUpperCase()).add(new TextItemPinned(item));
120 | }
121 | }
122 |
123 | GroupListWrapper groups = new GroupListWrapper();
124 |
125 | SortedSet keys = new TreeSet<>(new CompareItem());
126 |
127 | if (order == DESCENDING) {
128 | keys = ((TreeSet) keys).descendingSet();
129 | }
130 |
131 | keys.addAll(hashMap.keySet());
132 |
133 | for (String key : keys) {
134 | List values = hashMap.get(key);
135 | groups.addGroup(new Group(values, key));
136 | }
137 |
138 | return groups;
139 | }
140 |
141 | private static class CompareItem implements Comparator {
142 | private Collator collator;
143 |
144 | public CompareItem() {
145 | this(Locale.getDefault());
146 | }
147 |
148 | public CompareItem(Locale locale) {
149 | this.collator = Collator.getInstance(locale);
150 | }
151 |
152 | @Override
153 | public int compare(Object obj1, Object obj2) {
154 | if (obj1 instanceof String && obj2 instanceof String) {
155 | return collator.compare((String) obj1, (String) obj2);
156 | } else if (obj1 instanceof Selector && obj2 instanceof Selector) {
157 | return collator.compare(((Selector) obj1).select(), ((Selector) obj2).select());
158 | } else
159 | return 0;
160 | }
161 | }
162 |
163 | public interface Selector {
164 | String select();
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/pinnedlist/src/main/java/com/gvillani/pinnedlist/ImageItemPinned.java:
--------------------------------------------------------------------------------
1 | package com.gvillani.pinnedlist;
2 |
3 | public class ImageItemPinned extends ItemPinned {
4 | private int image;
5 |
6 | public ImageItemPinned(T item) {
7 | super(item);
8 | }
9 |
10 | public int getImage() {
11 | return image;
12 | }
13 |
14 | public void setImage(int image) {
15 | this.image = image;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/pinnedlist/src/main/java/com/gvillani/pinnedlist/ItemPinned.java:
--------------------------------------------------------------------------------
1 | package com.gvillani.pinnedlist;
2 |
3 | public class ItemPinned {
4 | private int groupSize;
5 | private int relativePosition;
6 | private T item;
7 |
8 | public ItemPinned(T item) {
9 | this.item = item;
10 | }
11 |
12 | public int getGroupSize() {
13 | return groupSize;
14 | }
15 |
16 | /**
17 | * Sets the size of the group. It should not be called explicitally
18 | *
19 | * @param groupSize
20 | */
21 | public void setGroupSize(int groupSize) {
22 | this.groupSize = groupSize;
23 | }
24 |
25 | public T getItem() {
26 | return item;
27 | }
28 |
29 | /**
30 | * Sets the position of the item inside the group. It should not be called explicitally
31 | *
32 | * @param relativePosition
33 | */
34 | public void setRelativePosition(int relativePosition) {
35 | this.relativePosition = relativePosition;
36 | }
37 |
38 | /**
39 | * Checks if the pin should appear in the current item. This happens when it is in position 0
40 | * @return TRUE if is visible. FALSE otherwise
41 | */
42 | public boolean isVisible() {
43 | if (relativePosition == 0) {
44 | return true;
45 | } else {
46 | return false;
47 | }
48 | }
49 |
50 | /**
51 | * Checks if the item is the last of the group
52 | * @return TRUE if is last. FALSE otherwise
53 | */
54 | public boolean isLast() {
55 | if (relativePosition == groupSize - 1) {
56 | return true;
57 | } else {
58 | return false;
59 | }
60 | }
61 | }
62 |
63 |
64 |
--------------------------------------------------------------------------------
/pinnedlist/src/main/java/com/gvillani/pinnedlist/PinBehavior.java:
--------------------------------------------------------------------------------
1 | package com.gvillani.pinnedlist;
2 |
3 | import android.graphics.Color;
4 | import android.os.Parcel;
5 | import android.os.Parcelable;
6 | import android.support.design.widget.CoordinatorLayout;
7 | import android.support.v4.view.ViewCompat;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.view.Gravity;
11 | import android.view.View;
12 | import android.widget.FrameLayout;
13 | import android.widget.ImageView;
14 | import android.widget.TextView;
15 |
16 | import java.util.List;
17 |
18 | /**
19 | * This class defines a Behavior for the floating indicator (image or text)
20 | */
21 | public class PinBehavior extends CoordinatorLayout.Behavior {
22 |
23 | private static final int DIRECTION_UP = 1;
24 | private static final int DIRECTION_DOWN = -1;
25 |
26 | private LinearLayoutManager mLayoutManager;
27 | private RecyclerView.Adapter mAdapter;
28 |
29 | private int mCurrentDirection;
30 | private int mCurrentOffset;
31 | private int mRelativeOffset;
32 |
33 | private int mItemHeight;
34 |
35 | private int mBaseColor;
36 | private boolean mFadeEffect;
37 | private boolean mPinInizialized;
38 | private boolean mIsCenteredVertical;
39 |
40 | private int mCurrentImage;
41 |
42 | private boolean mFirstLayout;
43 | private int mVerticalScrollOffset;
44 |
45 | private boolean restoredInstance;
46 |
47 | /**
48 | * @param fadeEffect TRUE if the floating pin should disappear with fade effect, FALSE otherwise
49 | * @param isCenteredVertical TRUE if the floating pin should be centered vertical respect to the RecyclerView item
50 | */
51 | public PinBehavior(boolean fadeEffect, boolean isCenteredVertical) {
52 | mFadeEffect = fadeEffect;
53 | mIsCenteredVertical = isCenteredVertical;
54 | }
55 |
56 | @Override
57 | public Parcelable onSaveInstanceState(CoordinatorLayout parent, View child) {
58 | View v = child.findViewById(R.id.pin);
59 | String text = null;
60 | if (v instanceof TextView) {
61 | text = ((TextView) v).getText() != null ? ((TextView) v).getText().toString() : null;
62 | }
63 |
64 | return new SavedState(super.onSaveInstanceState(parent, child), mCurrentOffset,
65 | text, mFadeEffect, mBaseColor, mPinInizialized, mItemHeight, mIsCenteredVertical,
66 | mRelativeOffset, mCurrentImage, mFirstLayout, mVerticalScrollOffset);
67 | }
68 |
69 | @Override
70 | public void onRestoreInstanceState(CoordinatorLayout parent, View child, Parcelable state) {
71 | SavedState ss = (SavedState) state;
72 | super.onRestoreInstanceState(parent, child, ss.getSuperState());
73 | restoredInstance = true;
74 | mCurrentOffset = ss.currentOffset;
75 | mPinInizialized = ss.labelInitialized;
76 | mCurrentImage = ss.currentImage;
77 | mFirstLayout = ss.isFirstLayout;
78 | mVerticalScrollOffset = ss.verticalScrollOffset;
79 |
80 | if (mPinInizialized) {
81 | child.setVisibility(View.VISIBLE);
82 | View v = child.findViewById(R.id.pin);
83 | if (v instanceof TextView) {
84 | ((TextView) v).setText(ss.currentText);
85 | } else if (v instanceof ImageView) {
86 | if (mCurrentImage != 0) {
87 | ((ImageView) v).setImageResource(mCurrentImage);
88 | }
89 | }
90 | }
91 |
92 | mFadeEffect = ss.isFadeEnabled;
93 | mBaseColor = ss.baseColor;
94 | mItemHeight = ss.itemHeight;
95 | mIsCenteredVertical = ss.isCenteredVertical;
96 | mRelativeOffset = ss.relOffset;
97 |
98 | if (mIsCenteredVertical) {
99 | centerVerticalPin(child);
100 | }
101 | }
102 |
103 | private void centerVerticalPin(View container) {
104 | View pin = container.findViewById(R.id.pin);
105 | CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) container.getLayoutParams();
106 | params.height = mItemHeight;
107 | container.setLayoutParams(params);
108 |
109 | FrameLayout.LayoutParams params1 = (FrameLayout.LayoutParams) pin.getLayoutParams();
110 | params1.gravity = Gravity.CENTER_VERTICAL;
111 | pin.setLayoutParams(params1);
112 | }
113 |
114 | @Override
115 | public boolean onLayoutChild(CoordinatorLayout parent, View child, int layoutDirection) {
116 |
117 | final View c = child;
118 |
119 | parent.onLayoutChild(child, layoutDirection);
120 |
121 | child.offsetTopAndBottom(-mCurrentOffset);
122 |
123 | final List dependencies = parent.getDependencies(child);
124 |
125 | if (dependencies.size() == 1 && dependencies.get(0) instanceof RecyclerView) {
126 | final RecyclerView recyclerView = (RecyclerView) dependencies.get(0);
127 | mAdapter = recyclerView.getAdapter();
128 |
129 | mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
130 | @Override
131 | public void onChanged() {
132 | //Log.e("TAG","something has changed");
133 | updateView(c, recyclerView, mVerticalScrollOffset - recyclerView.computeVerticalScrollOffset());
134 | }
135 | });
136 |
137 | if (mAdapter.getItemCount() > 0) {
138 | mItemHeight = recyclerView.getLayoutManager().getDecoratedMeasuredHeight((recyclerView).getChildAt(0));
139 | }
140 |
141 | mLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
142 | if (restoredInstance) {
143 | restoredInstance = false;
144 | updateView(child, recyclerView, mVerticalScrollOffset - recyclerView.computeVerticalScrollOffset());
145 | //updatePinContent(child);
146 | }
147 |
148 | if (mFirstLayout) {
149 | mFirstLayout = false;
150 | mRelativeOffset += recyclerView.getTop();
151 | }
152 | }
153 |
154 | child.offsetTopAndBottom(mRelativeOffset);
155 |
156 | if (mFadeEffect && mPinInizialized) {
157 | setAlpha(child);
158 | }
159 |
160 | return true;
161 | }
162 |
163 | @Override
164 | public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
165 | return dependency instanceof RecyclerView;
166 | }
167 |
168 | @Override
169 | public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
170 | int dependencyOffset = dependency.getTop();
171 | child.offsetTopAndBottom(dependencyOffset - mRelativeOffset);
172 | mRelativeOffset = dependencyOffset;
173 |
174 | return true;
175 | }
176 |
177 |
178 | @Override
179 | public void onNestedPreScroll(CoordinatorLayout coordinatorLayout,
180 | View child, View target,
181 | int dx, int dy,
182 | int[] consumed) {
183 |
184 | if (target instanceof RecyclerView) {
185 | if (!mPinInizialized)
186 | initPin(child);
187 | if (child.getVisibility() == View.INVISIBLE)
188 | child.setVisibility(View.VISIBLE);
189 | }
190 |
191 | mCurrentDirection = dy > 0 ? DIRECTION_UP : DIRECTION_DOWN;
192 | }
193 |
194 |
195 | @Override
196 | public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout,
197 | View child, View directTargetChild, View target,
198 | int nestedScrollAxes) {
199 |
200 | return (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;
201 | }
202 |
203 |
204 | @Override
205 | public void onNestedScroll(CoordinatorLayout coordinatorLayout,
206 | View child, View target,
207 | int dxConsumed, int dyConsumed,
208 | int dxUnconsumed, int dyUnconsumed) {
209 |
210 | if (target instanceof RecyclerView) {
211 | updateView(child, target, dyConsumed);
212 | }
213 | }
214 |
215 | private void updateView(View child, View target, int dy) {
216 | boolean isLastItem = isLastItemGroup();
217 |
218 | if (isLastItem) {
219 | mVerticalScrollOffset = ((RecyclerView) target).computeVerticalScrollOffset();
220 | int newOffset = mVerticalScrollOffset % mItemHeight;
221 | int increment = newOffset - mCurrentOffset;
222 | mCurrentOffset = newOffset;
223 |
224 | child.offsetTopAndBottom(-increment);
225 |
226 | if (mFadeEffect)
227 | setAlpha(child);
228 |
229 | if (mCurrentDirection == DIRECTION_DOWN ||
230 | (mCurrentDirection == DIRECTION_UP && increment < 0)) {
231 | updatePinContent(child);
232 | }
233 | } else {
234 |
235 | if (mCurrentOffset != 0 || dy > mItemHeight) {
236 | if (mCurrentOffset != 0) {
237 | child.offsetTopAndBottom(mCurrentOffset);
238 |
239 | mCurrentOffset = 0;
240 | if (mFadeEffect)
241 | removeAlpha(child);
242 |
243 | }
244 |
245 | updatePinContent(child);
246 | }
247 | }
248 | }
249 |
250 | @Override
251 | public boolean onNestedPreFling(CoordinatorLayout coordinatorLayout, final View child, View target, float velocityX, float velocityY) {
252 | if (target instanceof RecyclerView) {
253 |
254 | if (!mPinInizialized)
255 | initPin(child);
256 | if (child.getVisibility() == View.INVISIBLE)
257 | child.setVisibility(View.VISIBLE);
258 |
259 | mCurrentDirection = velocityY > 0 ? DIRECTION_UP : DIRECTION_DOWN;
260 |
261 | ((RecyclerView) target).clearOnScrollListeners();
262 | ((RecyclerView) target).addOnScrollListener(new RecyclerView.OnScrollListener() {
263 | @Override
264 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
265 | updateView(child, recyclerView, dy);
266 | }
267 |
268 | @Override
269 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
270 | if (newState == RecyclerView.SCROLL_STATE_IDLE) {
271 | if (recyclerView.computeVerticalScrollOffset() == 0) {
272 | mVerticalScrollOffset = 0;
273 | child.setVisibility(View.INVISIBLE);
274 | }
275 |
276 | updatePinContent(child);
277 | recyclerView.clearOnScrollListeners();
278 | }
279 | }
280 | });
281 | }
282 |
283 | return false;
284 | }
285 |
286 | private void updatePinContent(View container) {
287 |
288 | ItemPinned itemPinned = ((PinnedAdapter) mAdapter).getItem(mLayoutManager.findFirstVisibleItemPosition());
289 |
290 | View view = container.findViewById(R.id.pin);
291 |
292 | if (view instanceof TextView)
293 | changeText((TextView) view, (TextItemPinned) itemPinned);
294 | else if (view instanceof ImageView)
295 | changeImage((ImageView) view, (ImageItemPinned) itemPinned);
296 | }
297 |
298 | private void changeText(TextView view, TextItemPinned item) {
299 | view.setText(item.getLabel());
300 | }
301 |
302 | private void changeImage(ImageView view, ImageItemPinned item) {
303 | mCurrentImage = item.getImage();
304 | view.setImageResource(mCurrentImage);
305 | }
306 |
307 | private void initPin(View child) {
308 | mPinInizialized = true;
309 |
310 | View pin = child.findViewById(R.id.pin);
311 | if (mIsCenteredVertical) {
312 | centerVerticalPin(child);
313 | }
314 |
315 | updatePinContent(child);
316 |
317 | if (pin instanceof TextView)
318 | mBaseColor = ((TextView) pin).getCurrentTextColor();
319 |
320 | if (mFadeEffect) {
321 | setAlpha(child);
322 | }
323 | }
324 |
325 | private void setAlpha(View child) {
326 | View pin = child.findViewById(R.id.pin);
327 |
328 | if (pin instanceof TextView) {
329 | int currentAlpha = Color.alpha(mBaseColor);
330 | float alphaIncrement = (float) currentAlpha / (float) mItemHeight;
331 | int newAlpha = (int) (currentAlpha - mCurrentOffset * alphaIncrement);
332 | int newColor = Color.argb(newAlpha, Color.red(mBaseColor), Color.green(mBaseColor), Color.blue(mBaseColor));
333 |
334 | ((TextView) pin).setTextColor(newColor);
335 | }
336 | }
337 |
338 | private void removeAlpha(View child) {
339 | View pin = child.findViewById(R.id.pin);
340 |
341 | if (pin instanceof TextView) {
342 | ((TextView) pin).setTextColor(mBaseColor);
343 | }
344 | }
345 |
346 | private boolean isLastItemGroup() {
347 | ItemPinned item = ((PinnedAdapter) mAdapter).getItem(mLayoutManager.findFirstVisibleItemPosition());
348 | return item.isLast();
349 | }
350 |
351 | protected static class SavedState extends View.BaseSavedState {
352 |
353 | int currentOffset;
354 | String currentText;
355 | boolean isFadeEnabled;
356 | int baseColor;
357 | boolean labelInitialized;
358 | int itemHeight;
359 | boolean isCenteredVertical;
360 | int relOffset;
361 | int currentImage;
362 | boolean isFirstLayout;
363 | int verticalScrollOffset;
364 |
365 | public SavedState(Parcel source) {
366 | super(source);
367 |
368 | currentOffset = source.readInt();
369 | currentText = source.readString();
370 | isFadeEnabled = source.readInt() == 0 ? false : true;
371 | }
372 |
373 | public SavedState(Parcelable superState, int currentOffset, String currentText,
374 | boolean isFadeEnabled, int baseColor, boolean labelInitialized,
375 | int itemHeight, boolean isCenteredVertical, int relOffset,
376 | int currentImage, boolean isFirstLayout, int verticalScrollOffset) {
377 | super(superState);
378 | this.currentOffset = currentOffset;
379 | this.currentText = currentText;
380 | this.isFadeEnabled = isFadeEnabled;
381 | this.baseColor = baseColor;
382 | this.labelInitialized = labelInitialized;
383 | this.itemHeight = itemHeight;
384 | this.isCenteredVertical = isCenteredVertical;
385 | this.relOffset = relOffset;
386 | this.currentImage = currentImage;
387 | this.isFirstLayout = isFirstLayout;
388 | this.verticalScrollOffset = verticalScrollOffset;
389 | }
390 |
391 | @Override
392 | public void writeToParcel(Parcel out, int flags) {
393 | super.writeToParcel(out, flags);
394 | out.writeInt(currentOffset);
395 | out.writeString(currentText);
396 | out.writeInt(isFadeEnabled ? 1 : 0);
397 | out.writeInt(baseColor);
398 | out.writeInt(labelInitialized ? 1 : 0);
399 | out.writeInt(itemHeight);
400 | out.writeInt(isCenteredVertical ? 1 : 0);
401 | out.writeInt(relOffset);
402 | out.writeInt(isFirstLayout ? 1 : 0);
403 | out.writeInt(verticalScrollOffset);
404 | }
405 |
406 | public static final Creator CREATOR =
407 | new Creator() {
408 | @Override
409 | public SavedState createFromParcel(Parcel source) {
410 | return new SavedState(source);
411 | }
412 |
413 | @Override
414 | public SavedState[] newArray(int size) {
415 | return new SavedState[size];
416 | }
417 | };
418 | }
419 | }
--------------------------------------------------------------------------------
/pinnedlist/src/main/java/com/gvillani/pinnedlist/PinUtils.java:
--------------------------------------------------------------------------------
1 | package com.gvillani.pinnedlist;
2 |
3 | import android.content.Context;
4 | import android.util.DisplayMetrics;
5 |
6 | public class PinUtils {
7 | public static int dpToPx(Context context, int dp) {
8 | DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
9 | int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
10 | return px;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/pinnedlist/src/main/java/com/gvillani/pinnedlist/PinnedAdapter.java:
--------------------------------------------------------------------------------
1 | package com.gvillani.pinnedlist;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.ImageView;
7 | import android.widget.LinearLayout;
8 | import android.widget.TextView;
9 |
10 | /**
11 | * Custom Adapter that wraps the floating pin on the left side of the RecyclerView
12 | */
13 | public abstract class PinnedAdapter extends RecyclerView.Adapter {
14 | protected GroupListWrapper mListWrapper;
15 | private PinnedListLayout mLayout;
16 |
17 | public PinnedAdapter(GroupListWrapper listGroupWrapper, PinnedListLayout layout) {
18 | mListWrapper = listGroupWrapper;
19 | mLayout = layout;
20 | }
21 |
22 | /**
23 | * It returns the layout that has to be passed to the view holder.
24 | *
25 | * @param rowView the layout that has to be shown
26 | * @return a wrapped layout
27 | */
28 | public ViewGroup getRowLayout(View rowView) {
29 | LinearLayout rowLayout = mLayout.getContainerRowLayout();
30 | rowLayout.addView(rowView);
31 | return rowLayout;
32 | }
33 |
34 | @Override
35 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
36 |
37 | if (holder instanceof PinnedViewHolder) {
38 | ItemPinned currentItem = mListWrapper.getItemPinned(position);
39 |
40 | if (currentItem.isVisible()) {
41 | ((PinnedViewHolder) holder).viewPin.setVisibility(View.VISIBLE);
42 | } else {
43 | ((PinnedViewHolder) holder).viewPin.setVisibility(View.INVISIBLE);
44 | }
45 |
46 | if (currentItem instanceof TextItemPinned) {
47 | ((TextView) ((PinnedViewHolder) holder).viewPin)
48 | .setText(((TextItemPinned) currentItem).getLabel());
49 |
50 | } else if (currentItem instanceof ImageItemPinned) {
51 | ((ImageView) ((PinnedViewHolder) holder).viewPin)
52 | .setImageResource(((ImageItemPinned) currentItem).getImage());
53 | }
54 | }
55 | }
56 |
57 | @Override
58 | public int getItemCount() {
59 | if (mListWrapper == null || mListWrapper.size() == 0)
60 | return 0;
61 | else
62 | return mListWrapper.size();
63 | }
64 |
65 | public ItemPinned getItem(int position) {
66 | return mListWrapper.getItemPinned(position);
67 | }
68 | }
69 |
70 |
--------------------------------------------------------------------------------
/pinnedlist/src/main/java/com/gvillani/pinnedlist/PinnedListLayout.java:
--------------------------------------------------------------------------------
1 | package com.gvillani.pinnedlist;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Color;
6 | import android.graphics.drawable.ColorDrawable;
7 | import android.support.design.widget.CoordinatorLayout;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.util.AttributeSet;
10 | import android.util.TypedValue;
11 | import android.view.Gravity;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.widget.FrameLayout;
16 | import android.widget.ImageView;
17 | import android.widget.LinearLayout;
18 | import android.widget.TextView;
19 |
20 | /**
21 | * Created by Giuseppe on 09/04/2016.
22 | */
23 | public class PinnedListLayout extends CoordinatorLayout {
24 | private final static int TYPE_TEXTVIEW = 0;
25 | private final static int TYPE_IMAGEVIEW = 1;
26 |
27 | private final static int PIN_GRAVITY_TOP = 0;
28 | private final static int PIN_GRAVITY_CENTER = 1;
29 |
30 | private final static int DEFAULT_PIN_LAYOUT_WIDTH = 36;
31 | private final static int DEFAULT_PIN_LAYOUT_HEIGHT = 36;
32 | private final static int DEFAULT_PADDING = 3;
33 |
34 | private RecyclerView mRecyclerView;
35 | private FrameLayout mPinLayout;
36 |
37 | private int mPinLayoutHeight;
38 | private int mPinLayoutWidth;
39 |
40 | private int mPinVerticalPosition, mPinMarginLeft, mPinMarginRight, mPinMarginTop, mPinMarginBottom;
41 |
42 | private float mPinTextSize;
43 | private int mPinTextColor;
44 |
45 | private boolean mFadeEffect;
46 | private Behavior mBehavior;
47 |
48 | private int mType;
49 |
50 | public PinnedListLayout(Context context) {
51 | super(context);
52 | initializeViews(context);
53 | }
54 |
55 | public PinnedListLayout(Context context, AttributeSet attrs) {
56 | super(context, attrs);
57 | TypedArray a = context.getTheme().obtainStyledAttributes(
58 | attrs,
59 | R.styleable.PinnedListLayout,
60 | 0, 0);
61 |
62 | try {
63 |
64 | mType = a.getInteger(R.styleable.PinnedListLayout_type, TYPE_TEXTVIEW);
65 |
66 | if (a.hasValue(R.styleable.PinnedListLayout_layout_pin_width)) {
67 | try {
68 | mPinLayoutWidth = a.getInt(R.styleable.PinnedListLayout_layout_pin_width, ViewGroup.LayoutParams.WRAP_CONTENT);
69 | } catch (NumberFormatException e) {
70 | mPinLayoutWidth = a.getDimensionPixelSize(R.styleable.PinnedListLayout_layout_pin_width,
71 | PinUtils.dpToPx(context, DEFAULT_PIN_LAYOUT_WIDTH));
72 | }
73 | } else {
74 | if (mType == TYPE_TEXTVIEW)
75 | mPinLayoutWidth = ViewGroup.LayoutParams.WRAP_CONTENT;
76 | else if (mType == TYPE_IMAGEVIEW)
77 | mPinLayoutWidth = PinUtils.dpToPx(context, DEFAULT_PIN_LAYOUT_WIDTH);
78 | }
79 |
80 | if (a.hasValue(R.styleable.PinnedListLayout_layout_pin_height)) {
81 | try {
82 | mPinLayoutHeight = a.getInt(R.styleable.PinnedListLayout_layout_pin_height, ViewGroup.LayoutParams.WRAP_CONTENT);
83 | } catch (NumberFormatException e) {
84 | mPinLayoutHeight = a.getDimensionPixelSize(R.styleable.PinnedListLayout_layout_pin_height,
85 | PinUtils.dpToPx(context, DEFAULT_PIN_LAYOUT_HEIGHT));
86 | }
87 | } else {
88 | if (mType == TYPE_TEXTVIEW)
89 | mPinLayoutHeight = ViewGroup.LayoutParams.WRAP_CONTENT;
90 | else if (mType == TYPE_IMAGEVIEW)
91 | mPinLayoutHeight = PinUtils.dpToPx(context, DEFAULT_PIN_LAYOUT_WIDTH);
92 | }
93 |
94 | if (a.hasValue(R.styleable.PinnedListLayout_pin_margin)) {
95 | mPinMarginLeft = mPinMarginRight = mPinMarginTop = mPinMarginBottom =
96 | a.getDimensionPixelSize(R.styleable.PinnedListLayout_pin_margin,
97 | PinUtils.dpToPx(context, DEFAULT_PADDING));
98 | } else {
99 | mPinMarginLeft = a.getDimensionPixelSize(R.styleable.PinnedListLayout_pin_margin_left,
100 | PinUtils.dpToPx(context, DEFAULT_PADDING));
101 | mPinMarginRight = a.getDimensionPixelSize(R.styleable.PinnedListLayout_pin_margin_right,
102 | PinUtils.dpToPx(context, DEFAULT_PADDING));
103 | mPinMarginTop = a.getDimensionPixelSize(R.styleable.PinnedListLayout_pin_margin_top,
104 | PinUtils.dpToPx(context, DEFAULT_PADDING));
105 | mPinMarginBottom = a.getDimensionPixelSize(R.styleable.PinnedListLayout_pin_margin_bottom,
106 | PinUtils.dpToPx(context, DEFAULT_PADDING));
107 | }
108 |
109 | mPinTextSize = a.getDimensionPixelSize(R.styleable.PinnedListLayout_pin_text_size,
110 | PinUtils.dpToPx(context, -1));
111 |
112 | mFadeEffect = a.getBoolean(R.styleable.PinnedListLayout_fade_effect, false);
113 |
114 | mPinTextColor = a.getColor(R.styleable.PinnedListLayout_pin_text_color, -1);
115 |
116 | mPinVerticalPosition = a.getInt(R.styleable.PinnedListLayout_pin_vertical_position, PIN_GRAVITY_TOP);
117 |
118 | } finally {
119 | a.recycle();
120 | }
121 |
122 | initializeViews(context);
123 | }
124 |
125 | private void initializeViews(Context context) {
126 | LayoutInflater inflater = (LayoutInflater) context
127 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
128 | if (mType == TYPE_TEXTVIEW)
129 | inflater.inflate(R.layout.tv_indicator, this);
130 | else
131 | inflater.inflate(R.layout.iv_indicator, this);
132 | }
133 |
134 | @Override
135 | protected void onFinishInflate() {
136 | super.onFinishInflate();
137 |
138 | mRecyclerView = (RecyclerView) this.findViewById(R.id.custom_list);
139 | mRecyclerView.setHasFixedSize(true);
140 |
141 | mPinLayout = (FrameLayout) this.findViewById(R.id.layout_pin);
142 |
143 |
144 | int colorDrawable;
145 | try {
146 | colorDrawable = ((ColorDrawable) this.getBackground()).getColor();
147 | } catch (NullPointerException e) {
148 | // TODO: get the default background color
149 | colorDrawable = Color.parseColor("#EEEEEE");
150 | }
151 |
152 | int opaqueColor = Color.argb(255, Color.red(colorDrawable), Color.green(colorDrawable), Color.blue(colorDrawable));
153 |
154 | this.setBackgroundColor(opaqueColor);
155 | mPinLayout.setBackgroundColor(opaqueColor);
156 |
157 | View pin = mPinLayout.findViewById(R.id.pin);
158 | FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(mPinLayoutWidth, mPinLayoutHeight);
159 | pin.setLayoutParams(params);
160 | mPinLayout.setPadding(mPinMarginLeft, mPinMarginTop, mPinMarginRight, mPinMarginBottom);
161 |
162 | pin.setBackgroundColor(opaqueColor);
163 |
164 | if (mType == TYPE_TEXTVIEW) {
165 | if (mPinTextSize != -1)
166 | ((TextView) pin).setTextSize(TypedValue.COMPLEX_UNIT_PX, mPinTextSize);
167 | if (mPinTextColor != -1)
168 | ((TextView) pin).setTextColor(mPinTextColor);
169 | } else if (mType == TYPE_IMAGEVIEW) {
170 | // some operations for ImageView
171 | }
172 |
173 | setIndicatorAnimation();
174 | }
175 |
176 | private void setIndicatorAnimation() {
177 | CoordinatorLayout.LayoutParams params =
178 | (CoordinatorLayout.LayoutParams) mPinLayout.getLayoutParams();
179 | mBehavior = new PinBehavior(mFadeEffect, mPinVerticalPosition == PIN_GRAVITY_CENTER);
180 | params.setBehavior(mBehavior);
181 | mPinLayout.requestLayout();
182 | }
183 |
184 | /**
185 | * Return the RecyclerView wrapped in the layout
186 | *
187 | * @return {@link RecyclerView} object
188 | */
189 | public RecyclerView getRecyclerView() {
190 | return mRecyclerView;
191 | }
192 |
193 | /**
194 | * Returns the container for the row layout, that includes the floating pin
195 | * @return
196 | */
197 | public LinearLayout getContainerRowLayout() {
198 | LinearLayout ll = new LinearLayout(this.getContext());
199 | ll.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
200 | if (mPinVerticalPosition == PIN_GRAVITY_CENTER) {
201 | ll.setGravity(Gravity.CENTER_VERTICAL);
202 | }
203 | ll.setOrientation(LinearLayout.HORIZONTAL);
204 | FrameLayout frameLayout = (FrameLayout) getPinLayout();
205 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
206 | frameLayout.setLayoutParams(params);
207 | ll.addView(frameLayout);
208 |
209 | return ll;
210 | }
211 |
212 | private View getPinLayout() {
213 | FrameLayout pinLayout = new FrameLayout(this.getContext());
214 |
215 | pinLayout.setPadding(mPinLayout.getPaddingLeft(), mPinLayout.getPaddingTop(), mPinLayout.getPaddingRight(), mPinLayout.getPaddingBottom());
216 |
217 | if (mType == TYPE_TEXTVIEW) {
218 | TextView tvPin = ((TextView) mPinLayout.findViewById(R.id.pin));
219 |
220 | LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService
221 | (Context.LAYOUT_INFLATER_SERVICE);
222 | TextView tvLabel = (TextView) (inflater.inflate(R.layout.pin_tv, null));
223 | tvLabel.setLayoutParams(tvPin.getLayoutParams());
224 |
225 | tvLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, tvPin.getTextSize());
226 |
227 | if (mPinTextColor != -1)
228 | tvLabel.setTextColor(mPinTextColor);
229 |
230 | tvLabel.setId(R.id.fixed_pin_id);
231 |
232 | pinLayout.addView(tvLabel);
233 |
234 | } else if (mType == TYPE_IMAGEVIEW) {
235 | ImageView ivPin = ((ImageView) mPinLayout.findViewById(R.id.pin));
236 |
237 | ImageView ivLabel = new ImageView(this.getContext());
238 |
239 | ivLabel.setLayoutParams(ivPin.getLayoutParams());
240 | ivLabel.setId(R.id.fixed_pin_id);
241 |
242 | pinLayout.addView(ivLabel);
243 | }
244 |
245 | return pinLayout;
246 | }
247 | }
248 |
--------------------------------------------------------------------------------
/pinnedlist/src/main/java/com/gvillani/pinnedlist/PinnedRecyclerView.java:
--------------------------------------------------------------------------------
1 | package com.gvillani.pinnedlist;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.util.AttributeSet;
8 |
9 | public class PinnedRecyclerView extends RecyclerView {
10 |
11 | public PinnedRecyclerView(Context context) {
12 | super(context);
13 | setDefaultLayoutManager();
14 | }
15 |
16 | public PinnedRecyclerView(Context context, @Nullable AttributeSet attrs) {
17 | super(context, attrs);
18 | setDefaultLayoutManager();
19 | }
20 |
21 | public PinnedRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
22 | super(context, attrs, defStyle);
23 | setDefaultLayoutManager();
24 | }
25 |
26 | private void setDefaultLayoutManager() {
27 | setLayoutManager(new LinearLayoutManager(this.getContext()));
28 | }
29 |
30 | @Override
31 | public void setLayoutManager(LayoutManager layout) {
32 | if (getLayoutManager() == null) {
33 | super.setLayoutManager(layout);
34 | }
35 | }
36 |
37 | @Override
38 | public LayoutManager getLayoutManager() {
39 | return super.getLayoutManager();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/pinnedlist/src/main/java/com/gvillani/pinnedlist/PinnedViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.gvillani.pinnedlist;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.View;
5 |
6 | public class PinnedViewHolder extends RecyclerView.ViewHolder {
7 | protected View viewPin;
8 |
9 | public PinnedViewHolder(View itemView) {
10 | super(itemView);
11 | viewPin = itemView.findViewById(R.id.fixed_pin_id);
12 | }
13 | }
--------------------------------------------------------------------------------
/pinnedlist/src/main/java/com/gvillani/pinnedlist/TextItemPinned.java:
--------------------------------------------------------------------------------
1 | package com.gvillani.pinnedlist;
2 |
3 | /**
4 | * Created by Giuseppe on 08/04/2016.
5 | */
6 | public class TextItemPinned extends ItemPinned {
7 | private String label;
8 |
9 | public TextItemPinned(T item) {
10 | super(item);
11 | }
12 |
13 | public String getLabel() {
14 | return label;
15 | }
16 |
17 | public void setLabel(String label) {
18 | this.label = label;
19 | }
20 | }
--------------------------------------------------------------------------------
/pinnedlist/src/main/res/layout/iv_indicator.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
9 |
14 |
18 |
19 |
--------------------------------------------------------------------------------
/pinnedlist/src/main/res/layout/pin_tv.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/pinnedlist/src/main/res/layout/tv_indicator.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
9 |
14 |
16 |
17 |
--------------------------------------------------------------------------------
/pinnedlist/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/pinnedlist/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/pinnedlist/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PinnedList
3 |
4 |
--------------------------------------------------------------------------------
/pinnedlist/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
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
--------------------------------------------------------------------------------