├── .gitignore
├── LICENSE
├── MIGRATION.md
├── README.md
├── app
├── .gitignore
├── build.gradle
├── lint.xml
├── proguard-rules.pro
├── release
│ └── output.json
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── danielstone
│ │ └── materialaboutlibrarydemo
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── ic_launcher-web.png
│ ├── java
│ │ └── com
│ │ │ └── danielstone
│ │ │ └── materialaboutlibrarydemo
│ │ │ ├── Application.java
│ │ │ ├── Demo.java
│ │ │ ├── ExampleMaterialAboutActivity.java
│ │ │ ├── ExampleMaterialAboutFragment.java
│ │ │ ├── ExampleMaterialAboutFragmentActivity.java
│ │ │ ├── ExampleMaterialAboutLicenseActivity.java
│ │ │ ├── MainActivity.java
│ │ │ └── custom
│ │ │ ├── MyCustomItem.java
│ │ │ └── MyViewTypeManager.java
│ ├── res
│ │ ├── layout
│ │ │ ├── activity_example_material_about_fragment.xml
│ │ │ ├── activity_main.xml
│ │ │ ├── content_example_material_about_fragment.xml
│ │ │ ├── content_main.xml
│ │ │ ├── custom_item.xml
│ │ │ ├── mal_material_about_action_item_overridefornoicons.xml
│ │ │ └── mal_material_about_list_card_overrideforlistlayout.xml
│ │ ├── menu
│ │ │ ├── menu_example_material_about.xml
│ │ │ └── menu_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ ├── values
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── ic_launcher_background.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── xml
│ │ │ └── backup_descriptor.xml
│ └── web_hi_res_512.png
│ └── test
│ └── java
│ └── com
│ └── danielstone
│ └── materialaboutlibrarydemo
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── danielstone
│ │ └── materialaboutlibrary
│ │ ├── ConvenienceBuilder.java
│ │ ├── MaterialAboutActivity.java
│ │ ├── MaterialAboutFragment.java
│ │ ├── adapters
│ │ ├── MaterialAboutItemAdapter.java
│ │ └── MaterialAboutListAdapter.java
│ │ ├── holders
│ │ └── MaterialAboutItemViewHolder.java
│ │ ├── items
│ │ ├── MaterialAboutActionItem.java
│ │ ├── MaterialAboutItem.java
│ │ ├── MaterialAboutItemOnClickAction.java
│ │ └── MaterialAboutTitleItem.java
│ │ ├── model
│ │ ├── MaterialAboutCard.java
│ │ └── MaterialAboutList.java
│ │ └── util
│ │ ├── DefaultViewTypeManager.java
│ │ ├── OpenSourceLicense.java
│ │ └── ViewTypeManager.java
│ └── res
│ ├── color
│ └── mal_stroke_color.xml
│ ├── layout
│ ├── mal_material_about_action_item.xml
│ ├── mal_material_about_content.xml
│ ├── mal_material_about_list_card.xml
│ └── mal_material_about_title_item.xml
│ ├── values-cs
│ └── strings.xml
│ ├── values-de
│ └── strings.xml
│ ├── values-es
│ └── strings.xml
│ ├── values-uk
│ └── strings.xml
│ └── values
│ ├── attrs.xml
│ ├── colors.xml
│ ├── dimens.xml
│ ├── open_source_licenses.xml
│ ├── strings.xml
│ └── styles.xml
├── screenshots
├── 1.png
├── 2.png
└── 3.png
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows thumbnail db
2 | Thumbs.db
3 |
4 | # OSX files
5 | .DS_Store
6 |
7 | # built application files
8 | *.apk
9 | *.ap_
10 |
11 | # files for the dex VM
12 | *.dex
13 |
14 | # Java class files
15 | *.class
16 |
17 | # generated files
18 | bin/
19 | gen/
20 | build/
21 |
22 | # Local configuration file (sdk path, etc)
23 | local.properties
24 |
25 | # Eclipse project files
26 | .classpath
27 | .project
28 |
29 | # Android Studio
30 | .idea
31 | .gradle
32 | /*/local.properties
33 | /*/out
34 | /*/*/build
35 | build
36 | /*/*/production
37 | *.iml
38 | *.iws
39 | *.ipr
40 | *~
41 | *.swp
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/MIGRATION.md:
--------------------------------------------------------------------------------
1 | # Migration Guide
2 |
3 | ### Release 3.2.0
4 |
5 | * RecycledViewPool is now used to improve performance in longer lists
6 |
7 | * Change back to old style of card with elevation and no outline with `.outline(false)` on your card builder.
8 |
9 | ### Release 3.1.0
10 |
11 | * New layout shouldn't cause any issues.
12 |
13 | * Themes no longer need to be extending a Mal prefixed theme - use MaterialComponents themes as in the following example.
14 |
15 | * Layout no longer includes a toolbar - use a theme which includes one:
16 |
17 | ```xml
18 |
24 | ```
25 |
26 | * Custom card backgrounds can be defined as so:
27 |
28 | ```xml
29 |
41 | ```
42 |
43 | * You no longer need to define colours for your icons - let the library handle this, or set a custom colour with `colorOnSurface` attribute in your theme.
44 |
45 |
46 |
47 | ### Release 2.3.0
48 |
49 | * Changed design of layout, check old layouts
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # material-about-library
2 |
3 | [![Release][101]][102]  [](https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/master/LICENSE) [](https://github.com/daniel-stoneuk/material-about-library/issues)
4 |
5 | Makes it easy to create a beautiful about screen for your app. Generates an `Activity` or `Fragment`.
6 |
7 | Idea from here: [Heinrich Reimer's open-source-library-request-manager][6]
8 |
9 | Design inspired by [Phonograph](https://github.com/kabouzeid/Phonograph)
10 |
11 | If you use this library in your app, please let me know and I'll add it to the list.
12 |
13 | ## Demo
14 |
15 |
16 |
17 | ## Screenshots
18 |
19 | | Light | Dark | Custom Cardview Background |
20 | | ------------------------------ | ------------------------------ | ------------------------------ |
21 | |  |  |  |
22 |
23 | ## Features
24 |
25 | - Material design
26 | - Modular backend
27 | - Easy to implement
28 | - Simple but intuitive API
29 | - Dynamic item support
30 |
31 | ## Dependency
32 |
33 | _material-about-library_ is available on [**jitpack.io**][1].
34 |
35 | **Gradle dependency:**
36 |
37 | ```gradle
38 | allprojects {
39 | repositories {
40 | maven { url 'https://jitpack.io' }
41 | }
42 | }
43 | ```
44 |
45 | ```gradle
46 | dependencies {
47 | implementation 'com.github.daniel-stoneuk:material-about-library:3.1.2'
48 | }
49 | ```
50 |
51 | Help test `3.2.0` with shared views between adapters (may cause crashes):
52 |
53 | ```gradle
54 | dependencies {
55 | implementation 'com.github.daniel-stoneuk:material-about-library:3.2.0-rc01'
56 | }
57 | ```
58 |
59 | ## Migration
60 |
61 | View the migration guide [here](/MIGRATION.md)
62 |
63 | ## Setup
64 |
65 | ### Activity
66 |
67 | Your `Activity` must extend [`MaterialAboutActivity`][materialaboutactivityjava] and be in your _AndroidManifest.xml_:
68 |
69 | ```java
70 | public class ExampleMaterialAboutActivity extends MaterialAboutActivity {
71 |
72 | @Override
73 | @NonNull
74 | protected MaterialAboutList getMaterialAboutList(@NonNull Context context) {
75 | return new MaterialAboutList.Builder()
76 | .build(); // This creates an empty screen, add cards with .addCard()
77 | }
78 |
79 | @Override
80 | protected CharSequence getActivityTitle() {
81 | return getString(R.string.mal_title_about);
82 | }
83 |
84 | }
85 | ```
86 |
87 | Ensure that the theme extends a `MaterialComponents` theme, and apply primary & secondary colours:
88 |
89 | ```xml
90 |
91 |
92 |
94 |
95 |
96 | ```
97 |
98 | ```xml
99 |
103 | ```
104 |
105 | ### Fragment
106 |
107 | Your `Fragment` must extend [`MaterialAboutFragment`][materialaboutfragmentjava].
108 |
109 | ```java
110 | public class ExampleMaterialAboutFragment extends MaterialAboutFragment {
111 |
112 | @Override
113 | protected MaterialAboutList getMaterialAboutList(final Context activityContext) {
114 | return new MaterialAboutList.Builder()
115 | .build(); // This creates an empty screen, add cards with .addCard()
116 | }
117 |
118 | }
119 | ```
120 |
121 | Theming will follow the activity theme.
122 |
123 | ### Add Cards:
124 |
125 | Start building a "card" using [`MaterialAboutCard.Builder()`][8]
126 |
127 | ```java
128 | public class ExampleMaterialAboutActivity extends MaterialAboutActivity {
129 |
130 | @Override
131 | @NonNull
132 | protected MaterialAboutList getMaterialAboutList(@NonNull Context context) {
133 | MaterialAboutCard card = new MaterialAboutCard.Builder()
134 | // Configure card here
135 | .build();
136 |
137 | return new MaterialAboutList.Builder()
138 | .addCard(card)
139 | .build();
140 | }
141 | }
142 | ```
143 |
144 | Give the card a title by calling `.title()` on the `MaterialAboutCard.Builder`
145 |
146 | ```java
147 | MaterialAboutCard card = new MaterialAboutCard.Builder()
148 | .title("Author")
149 | .build();
150 | ```
151 |
152 |
153 | Enable elevation and disable the outline to get a more classic design by calling `.outline(false)` on the `MaterialAboutCard.Builder`
154 |
155 | ```java
156 | MaterialAboutCard card = new MaterialAboutCard.Builder()
157 | .outline(false)
158 | .build();
159 | ```
160 |
161 | ### Add Items to a card:
162 |
163 | There are currently two types of items you can add to a card - [`MaterialAboutTitleItem`][9] and [`MaterialAboutActionItem`][10]. Other types of items are planned, for example "person" items which feature buttons to showcase a single person. Feel free to submit a PR or Issue for more item ideas.
164 |
165 | - `MaterialAboutActionItem`: Standard item with text, icon and optional subtext.
166 | - `MaterialAboutTitleItem`: Larger item with large icon (e.g. app icon) and larger text.
167 |
168 | [`MaterialAboutTitleItem`][9] is created with [`MaterialAboutTitleItem.Builder()`][9] and lets you specify **text** and an **icon**.
169 |
170 | ```java
171 | MaterialAboutCard.Builder cardBuilder = new MaterialAboutCard.Builder();
172 | cardBuilder.addItem(new MaterialAboutTitleItem.Builder()
173 | .text("Material About Library")
174 | .icon(R.mipmap.ic_launcher)
175 | .build());
176 | ```
177 |
178 | [`MaterialAboutActionItem`][10] is created with [`MaterialAboutActionItem.Builder()`][10] and lets you specify **text**, **sub-text**, an **icon** and an **OnClickAction**.
179 |
180 | ```java
181 | cardBuilder.addItem(new MaterialAboutActionItem.Builder()
182 | .text("Version")
183 | .subText("1.0.0")
184 | .icon(R.drawable.ic_about_info)
185 | .setOnClickAction(new MaterialAboutActionItem.OnClickAction() {
186 | @Override
187 | public void onClick() {
188 | Toast.makeText(ExampleMaterialAboutActivity.this, "Version Tapped", Toast.LENGTH_SHORT)
189 | .show();
190 | }
191 | })
192 | .build());
193 | ```
194 |
195 | ### Return the list:
196 |
197 | Create a [`MaterialAboutList`][11] using [`MaterialAboutList.Builder()`][11], passing in the cards you would like to display.
198 |
199 | ```java
200 | MaterialAboutCard card = new MaterialAboutCard.Builder()
201 | .title("Hey! I'm a card")
202 | .build();
203 |
204 | return new MaterialAboutList.Builder()
205 | .addCard(card)
206 | .build();
207 | ```
208 |
209 | Check out a working example in [`Demo.java`][3].
210 |
211 | **Tip:** You can either use _Strings_ / _Drawables_ or _Resources_ when creating `MaterialAboutItem`'s
212 |
213 | **Tip:** Use [Android-Iconics][iconics] for icons. "Android-Iconics - Use any icon font, or vector (.svg) as drawable in your application."
214 |
215 | **Tip:** Use [ConvenienceBuilder][conveniencebuilderjava] to easily create items or OnClickActions.
216 |
217 | **Tip:** Customise text colour and card colour in your styles. Example below:
218 |
219 | ```xml
220 |
229 | ```
230 |
231 | ### Custom Adapters:
232 | It is possible to replace the contents of a card with a custom adapter. If you do this, then none of the items associated with the card will be displayed. Check out the demo app, in which use [LicenseAdapter](https://github.com/yshrsmz/LicenseAdapter) (hence the INTERNET permission).
233 |
234 | ```java
235 | MaterialAboutCard.Builder customAdapterCardBuilder = new MaterialAboutCard.Builder();
236 | // Create list of libraries
237 | List libraries = new ArrayList<>();
238 |
239 | // Add libraries that are hosted on GitHub with an Apache v2 license.
240 | libraries.add(Licenses.fromGitHubApacheV2("yshrsmz/LicenseAdapter"));
241 | libraries.add(Licenses.fromGitHubApacheV2("daniel-stoneuk/material-about-library"));
242 |
243 | customAdapterCardBuilder.title("Custom Adapter (License Adapter)");
244 | customAdapterCardBuilder.customAdapter(new LicenseAdapter(libraries));
245 | });
246 | ```
247 |
248 |
249 | ### Dynamic items:
250 | It's possible to create dynamic items that either change on tap (or when any other event occurs). There are two examples in the sample application. Simply change the items in the list variable and then call `refreshMaterialAboutList()`. DiffUtil calculates the changes to animate in the RecyclerView.
251 |
252 | ```java
253 | final MaterialAboutActionItem item = new MaterialAboutActionItem.Builder()
254 | .text("Dynamic UI")
255 | .subText(subText)
256 | .icon(new IconicsDrawable(c)
257 | .icon(CommunityMaterial.Icon.cmd_refresh)
258 | .color(ContextCompat.getColor(c, R.color.mal_color_icon_dark_theme)
259 | ).sizeDp(18))
260 | .build();
261 | item.setOnClickAction(new MaterialAboutItemOnClickAction() {
262 | @Override
263 | public void onClick() {
264 | item.setSubText("Random number: " + ((int) (Math.random() * 10)));
265 | refreshMaterialAboutList();
266 | }
267 | });
268 | ```
269 |
270 | ### Custom card and Action layout
271 | To get a layout that is similar to the 6th screenshot above simply override the files `mal_material_about_action_item` and `mal_material_about_list_card` by creating new layout resources with the same filename. See [here](https://github.com/daniel-stoneuk/material-about-library/tree/master/app/src/main/res/layout).
272 |
273 | ## Contributors
274 |
275 | - Daniel Stone ([@daniel-stoneuk](https://github.com/daniel-stoneuk))
276 | - Robert Pösel ([@Robyer](https://github.com/Robyer))
277 | - Jonas Uekötter ([@ueman](https://github.com/ueman))
278 | - Rainer Lang ([@Rainer-Lang](https://github.com/rainer-lang))
279 | - Sebastian Guillen ([@code-schreiber](https://github.com/code-schreiber))
280 | - and [others](https://github.com/daniel-stoneuk/material-about-library/graphs/contributors)
281 |
282 | ## Apps using this library
283 |
284 | - [Monitor for EnergyHive & Engage][5]
285 | - [Crafting Assistant NMS](https://play.google.com/store/apps/details?id=biemann.android.craftingnms)
286 | - [ComicsDB Client](https://play.google.com/store/apps/details?id=cz.kutner.comicsdbclient.comicsdbclient), code available on [GitHub](https://github.com/tukak/comicsdbclient)
287 | - [Android About Box](https://github.com/eggheadgames/android-about-box) (library) - an opinionated About Box for Android
288 | - [Skin Widget for Minecraft](https://play.google.com/store/apps/details?id=com.rabross.android.minecraftskinwidget)
289 | - [FastHub for GitHub](https://play.google.com/store/apps/details?id=com.fastaccess.github)
290 |
291 | ## License
292 |
293 | ```
294 | Copyright 2016-2020 Daniel Stone
295 |
296 | Licensed under the Apache License, Version 2.0 (the "License");
297 | you may not use this file except in compliance with the License.
298 | You may obtain a copy of the License at
299 |
300 | http://www.apache.org/licenses/LICENSE-2.0
301 |
302 | Unless required by applicable law or agreed to in writing, software
303 | distributed under the License is distributed on an "AS IS" BASIS,
304 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
305 | See the License for the specific language governing permissions and
306 | limitations under the License.
307 | ```
308 |
309 | [1]: https://jitpack.io/#daniel-stoneuk/material-about-library
310 | [2]: http://i.imgur.com/xXWDmLb.png
311 | [3]: https://github.com/daniel-stoneuk/material-about-library/blob/master/app/src/main/java/com/danielstone/materialaboutlibrarydemo/Demo.java
312 | [4]: http://i.imgur.com/HEm08Ax.png
313 | [5]: https://play.google.com/store/apps/details?id=com.danielstone.energyhive
314 | [6]: https://github.com/HeinrichReimer/open-source-library-request-manager/issues/3
315 | [8]: https://github.com/daniel-stoneuk/material-about-library/blob/master/library/src/main/java/com/danielstone/materialaboutlibrary/model/MaterialAboutCard.java
316 | [9]: https://github.com/daniel-stoneuk/material-about-library/blob/master/library/src/main/java/com/danielstone/materialaboutlibrary/model/MaterialAboutTitleItem.java
317 | [10]: https://github.com/daniel-stoneuk/material-about-library/blob/master/library/src/main/java/com/danielstone/materialaboutlibrary/model/MaterialAboutActionItem.java
318 | [11]: https://github.com/daniel-stoneuk/material-about-library/blob/master/library/src/main/java/com/danielstone/materialaboutlibrary/model/MaterialAboutList.java
319 | [101]: https://jitpack.io/v/daniel-stoneuk/material-about-library.svg
320 | [102]: https://jitpack.io/#daniel-stoneuk/material-about-library
321 | [conveniencebuilderjava]: https://github.com/daniel-stoneuk/material-about-library/blob/master/library/src/main/java/com/danielstone/materialaboutlibrary/ConvenienceBuilder.java
322 | [iconics]: https://github.com/mikepenz/Android-Iconics
323 | [materialaboutactivityjava]: https://github.com/daniel-stoneuk/material-about-library/blob/master/library/src/main/java/com/danielstone/materialaboutlibrary/MaterialAboutActivity.java
324 | [materialaboutfragmentjava]: https://github.com/daniel-stoneuk/material-about-library/blob/master/app/src/main/java/com/danielstone/materialaboutlibrarydemo/ExampleMaterialAboutFragment.java
325 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | def versionMajor = 3
4 | def versionMinor = 1
5 | def versionPatch = 2
6 | def versionBuild = 0 // bump for dogfood builds, public betas, etc.
7 |
8 | android {
9 | compileSdkVersion rootProject.ext.compileSdkVersion
10 |
11 | defaultConfig {
12 | applicationId "com.danielstone.materialaboutlibrarydemo"
13 | minSdkVersion 15
14 | targetSdkVersion rootProject.ext.targetSdkVersion
15 | versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
16 | versionName "${versionMajor}.${versionMinor}" + (versionPatch == 0 ? "" : ".${versionPatch}")
17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18 | }
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 | androidTestImplementation('androidx.test.espresso:espresso-core:3.3.0-alpha04', {
30 | exclude group: 'com.android.support', module: 'support-annotations'
31 | })
32 |
33 | implementation project(':library')
34 | implementation "androidx.appcompat:appcompat:$appCompatVersion"
35 | implementation "com.google.android.material:material:$materialVersion"
36 | implementation "com.mikepenz:iconics-core:2.9.5@aar"
37 | implementation 'com.mikepenz:community-material-typeface:2.0.46.1@aar'
38 | implementation 'net.yslibrary.licenseadapter:licenseadapter:3.0.0'
39 |
40 | testImplementation 'junit:junit:4.13'
41 | }
42 |
--------------------------------------------------------------------------------
/app/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/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 /Users/danielstone/Library/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/release/output.json:
--------------------------------------------------------------------------------
1 | [{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":30000,"versionName":"3.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release","dirName":""},"path":"app-release.apk","properties":{}}]
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/danielstone/materialaboutlibrarydemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrarydemo;
2 |
3 | import android.content.Context;
4 | import androidx.test.InstrumentationRegistry;
5 | import androidx.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.danielstone.materialaboutlibrarydemo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
17 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
30 |
33 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/app/src/main/java/com/danielstone/materialaboutlibrarydemo/Application.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrarydemo;
2 |
3 |
4 | public class Application extends android.app.Application {
5 |
6 | @Override public void onCreate() {
7 | super.onCreate();
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/danielstone/materialaboutlibrarydemo/Demo.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrarydemo;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.graphics.Color;
6 | import android.net.Uri;
7 |
8 | import androidx.core.content.ContextCompat;
9 |
10 | import com.danielstone.materialaboutlibrary.ConvenienceBuilder;
11 | import com.danielstone.materialaboutlibrary.items.MaterialAboutActionItem;
12 | import com.danielstone.materialaboutlibrary.items.MaterialAboutItemOnClickAction;
13 | import com.danielstone.materialaboutlibrary.items.MaterialAboutTitleItem;
14 | import com.danielstone.materialaboutlibrary.model.MaterialAboutCard;
15 | import com.danielstone.materialaboutlibrary.model.MaterialAboutList;
16 | import com.danielstone.materialaboutlibrary.util.OpenSourceLicense;
17 | import com.mikepenz.community_material_typeface_library.CommunityMaterial;
18 | import com.mikepenz.iconics.IconicsDrawable;
19 |
20 | public class Demo {
21 |
22 | public static MaterialAboutList createMaterialAboutList(final Context c, final int theme) {
23 | MaterialAboutCard.Builder appCardBuilder = new MaterialAboutCard.Builder();
24 |
25 | // Add items to card
26 |
27 | appCardBuilder.addItem(new MaterialAboutTitleItem.Builder()
28 | .text("Material About Library")
29 | .desc("© 2020 Daniel Stone")
30 | .icon(R.mipmap.ic_launcher)
31 | .build());
32 |
33 | appCardBuilder.addItem(ConvenienceBuilder.createVersionActionItem(c,
34 | new IconicsDrawable(c)
35 | .icon(CommunityMaterial.Icon.cmd_information_outline)
36 | .sizeDp(18),
37 | "Version",
38 | false));
39 |
40 | appCardBuilder.addItem(new MaterialAboutActionItem.Builder()
41 | .text("Changelog")
42 | .icon(new IconicsDrawable(c)
43 | .icon(CommunityMaterial.Icon.cmd_history)
44 | .sizeDp(18))
45 | .setOnClickAction(ConvenienceBuilder.createWebViewDialogOnClickAction(c, "Releases", "https://github.com/daniel-stoneuk/material-about-library/releases", true, false))
46 | .build());
47 |
48 | appCardBuilder.addItem(new MaterialAboutActionItem.Builder()
49 | .text("Licenses")
50 | .icon(new IconicsDrawable(c)
51 | .icon(CommunityMaterial.Icon.cmd_book)
52 | .sizeDp(18))
53 | .setOnClickAction(new MaterialAboutItemOnClickAction() {
54 | @Override
55 | public void onClick() {
56 | Intent intent = new Intent(c, ExampleMaterialAboutLicenseActivity.class);
57 | intent.putExtra(ExampleMaterialAboutActivity.THEME_EXTRA, theme);
58 | c.startActivity(intent);
59 | }
60 | })
61 | .build());
62 |
63 | MaterialAboutCard.Builder authorCardBuilder = new MaterialAboutCard.Builder();
64 | authorCardBuilder.title("Author");
65 | // authorCardBuilder.titleColor(ContextCompat.getColor(c, R.color.colorAccent));
66 |
67 | authorCardBuilder.addItem(new MaterialAboutActionItem.Builder()
68 | .text("Daniel Stone")
69 | .subText("United Kingdom")
70 | .icon(new IconicsDrawable(c)
71 | .icon(CommunityMaterial.Icon.cmd_account)
72 | .sizeDp(18))
73 | .build());
74 |
75 | authorCardBuilder.addItem(new MaterialAboutActionItem.Builder()
76 | .text("Fork on GitHub")
77 | .icon(new IconicsDrawable(c)
78 | .icon(CommunityMaterial.Icon.cmd_github_circle)
79 | .sizeDp(18))
80 | .setOnClickAction(ConvenienceBuilder.createWebsiteOnClickAction(c, Uri.parse("https://github.com/daniel-stoneuk")))
81 | .build());
82 |
83 | MaterialAboutCard.Builder convenienceCardBuilder = new MaterialAboutCard.Builder();
84 |
85 | convenienceCardBuilder.title("Convenience Builder");
86 |
87 | convenienceCardBuilder.addItem(ConvenienceBuilder.createVersionActionItem(c,
88 | new IconicsDrawable(c)
89 | .icon(CommunityMaterial.Icon.cmd_information_outline)
90 | .sizeDp(18),
91 | "Version",
92 | false));
93 |
94 | convenienceCardBuilder.addItem(ConvenienceBuilder.createWebsiteActionItem(c,
95 | new IconicsDrawable(c)
96 | .icon(CommunityMaterial.Icon.cmd_earth)
97 | .sizeDp(18),
98 | "Visit Website",
99 | true,
100 | Uri.parse("http://danstone.uk")));
101 |
102 | convenienceCardBuilder.addItem(ConvenienceBuilder.createRateActionItem(c,
103 | new IconicsDrawable(c)
104 | .icon(CommunityMaterial.Icon.cmd_star)
105 | .sizeDp(18),
106 | "Rate this app",
107 | null
108 | ));
109 |
110 | convenienceCardBuilder.addItem(ConvenienceBuilder.createEmailItem(c,
111 | new IconicsDrawable(c)
112 | .icon(CommunityMaterial.Icon.cmd_email)
113 | .sizeDp(18),
114 | "Send an email",
115 | true,
116 | "apps@danstone.uk",
117 | "Question concerning MaterialAboutLibrary"));
118 |
119 | convenienceCardBuilder.addItem(ConvenienceBuilder.createPhoneItem(c,
120 | new IconicsDrawable(c)
121 | .icon(CommunityMaterial.Icon.cmd_phone)
122 | .sizeDp(18),
123 | "Call me",
124 | true,
125 | "+44 12 3456 7890"));
126 |
127 | convenienceCardBuilder.addItem(ConvenienceBuilder.createMapItem(c,
128 | new IconicsDrawable(c)
129 | .icon(CommunityMaterial.Icon.cmd_map)
130 | .sizeDp(18),
131 | "Visit London",
132 | null,
133 | "London Eye"));
134 |
135 | MaterialAboutCard.Builder otherCardBuilder = new MaterialAboutCard.Builder();
136 | otherCardBuilder.title("Other");
137 | otherCardBuilder.outline(false);
138 |
139 | otherCardBuilder.cardColor(Color.parseColor("#c0cfff"));
140 |
141 | otherCardBuilder.addItem(new MaterialAboutActionItem.Builder()
142 | .icon(new IconicsDrawable(c)
143 | .icon(CommunityMaterial.Icon.cmd_language_html5)
144 | .sizeDp(18))
145 | .text("HTML Formatted Sub Text")
146 | .subTextHtml("This is HTML formatted text
This is very cool because it allows lines to get very long which can lead to all kinds of possibilities.
And line breaks.
Oh and by the way, this card has a custom defined background.")
147 | .setIconGravity(MaterialAboutActionItem.GRAVITY_TOP)
148 | .build()
149 | );
150 |
151 | return new MaterialAboutList(appCardBuilder.build(), authorCardBuilder.build(), convenienceCardBuilder.build(), otherCardBuilder.build());
152 | }
153 |
154 | public static MaterialAboutList createMaterialAboutLicenseList(final Context c) {
155 |
156 | MaterialAboutCard materialAboutLibraryLicenseCard = ConvenienceBuilder.createLicenseCard(c,
157 | new IconicsDrawable(c)
158 | .icon(CommunityMaterial.Icon.cmd_book)
159 | .sizeDp(18),
160 | "material-about-library", "2016", "Daniel Stone",
161 | OpenSourceLicense.APACHE_2);
162 |
163 | MaterialAboutCard androidIconicsLicenseCard = ConvenienceBuilder.createLicenseCard(c,
164 | new IconicsDrawable(c)
165 | .icon(CommunityMaterial.Icon.cmd_book)
166 | .sizeDp(18),
167 | "Android Iconics", "2016", "Mike Penz",
168 | OpenSourceLicense.APACHE_2);
169 |
170 | MaterialAboutCard leakCanaryLicenseCard = ConvenienceBuilder.createLicenseCard(c,
171 | new IconicsDrawable(c)
172 | .icon(CommunityMaterial.Icon.cmd_book)
173 | .sizeDp(18),
174 | "LeakCanary", "2015", "Square, Inc",
175 | OpenSourceLicense.APACHE_2);
176 |
177 | MaterialAboutCard mitLicenseCard = ConvenienceBuilder.createLicenseCard(c,
178 | new IconicsDrawable(c)
179 | .icon(CommunityMaterial.Icon.cmd_book)
180 | .sizeDp(18),
181 | "MIT Example", "2017", "Matthew Ian Thomson",
182 | OpenSourceLicense.MIT);
183 |
184 | MaterialAboutCard gplLicenseCard = ConvenienceBuilder.createLicenseCard(c,
185 | new IconicsDrawable(c)
186 | .icon(CommunityMaterial.Icon.cmd_book)
187 | .sizeDp(18),
188 | "GPL Example", "2017", "George Perry Lindsay",
189 | OpenSourceLicense.GNU_GPL_3);
190 |
191 | return new MaterialAboutList(materialAboutLibraryLicenseCard,
192 | androidIconicsLicenseCard,
193 | leakCanaryLicenseCard,
194 | mitLicenseCard,
195 | gplLicenseCard);
196 | }
197 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/danielstone/materialaboutlibrarydemo/ExampleMaterialAboutActivity.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrarydemo;
2 |
3 | import android.content.Context;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 | import androidx.annotation.NonNull;
7 | import androidx.annotation.Nullable;
8 | import com.google.android.material.snackbar.Snackbar;
9 | import androidx.core.content.ContextCompat;
10 | import android.util.Log;
11 | import android.view.Menu;
12 | import android.view.MenuItem;
13 | import android.widget.Toast;
14 |
15 | import com.danielstone.materialaboutlibrary.ConvenienceBuilder;
16 | import com.danielstone.materialaboutlibrary.MaterialAboutActivity;
17 | import com.danielstone.materialaboutlibrary.items.MaterialAboutActionItem;
18 | import com.danielstone.materialaboutlibrary.items.MaterialAboutItemOnClickAction;
19 | import com.danielstone.materialaboutlibrary.items.MaterialAboutTitleItem;
20 | import com.danielstone.materialaboutlibrary.model.MaterialAboutCard;
21 | import com.danielstone.materialaboutlibrary.model.MaterialAboutList;
22 | import com.danielstone.materialaboutlibrary.util.ViewTypeManager;
23 | import com.danielstone.materialaboutlibrarydemo.custom.MyCustomItem;
24 | import com.danielstone.materialaboutlibrarydemo.custom.MyViewTypeManager;
25 | import com.mikepenz.community_material_typeface_library.CommunityMaterial;
26 | import com.mikepenz.iconics.IconicsDrawable;
27 |
28 | import net.yslibrary.licenseadapter.Library;
29 | import net.yslibrary.licenseadapter.LicenseAdapter;
30 | import net.yslibrary.licenseadapter.Licenses;
31 |
32 | import java.util.ArrayList;
33 | import java.util.List;
34 |
35 | public class ExampleMaterialAboutActivity extends MaterialAboutActivity {
36 |
37 | public static final String THEME_EXTRA = "";
38 | public static final int THEME_LIGHT = 0;
39 | public static final int THEME_DARK = 1;
40 | public static final int THEME_DAYNIGHT = 2;
41 | public static final int THEME_CUSTOM_CARDVIEW = 3;
42 |
43 | @NonNull
44 | @Override
45 | protected MaterialAboutList getMaterialAboutList(@NonNull final Context c) {
46 | MaterialAboutCard.Builder advancedCardBuilder = new MaterialAboutCard.Builder();
47 | advancedCardBuilder.title("Advanced");
48 |
49 | advancedCardBuilder.addItem(new MaterialAboutTitleItem.Builder()
50 | .text("TitleItem OnClickAction")
51 | .icon(R.mipmap.ic_launcher)
52 | .setOnClickAction(ConvenienceBuilder.createWebsiteOnClickAction(c, Uri.parse("http://www.danstone.uk")))
53 | .build());
54 |
55 | advancedCardBuilder.addItem(new MaterialAboutActionItem.Builder()
56 | .text("Snackbar demo")
57 | .icon(new IconicsDrawable(c)
58 | .icon(CommunityMaterial.Icon.cmd_code_tags)
59 | .sizeDp(18))
60 | .setOnClickAction(new MaterialAboutItemOnClickAction() {
61 | @Override
62 | public void onClick() {
63 | Snackbar.make(getRecyclerView(), "Test", Snackbar.LENGTH_SHORT).show();
64 | }
65 | })
66 | .build());
67 |
68 | advancedCardBuilder.addItem(new MaterialAboutActionItem.Builder()
69 | .text("OnLongClickAction demo")
70 | .icon(new IconicsDrawable(c)
71 | .icon(CommunityMaterial.Icon.cmd_hand_pointing_right)
72 | .sizeDp(18))
73 | .setOnLongClickAction(new MaterialAboutItemOnClickAction() {
74 | @Override
75 | public void onClick() {
76 | Toast.makeText(c, "Long pressed", Toast.LENGTH_SHORT).show();
77 | }
78 | })
79 | .build());
80 |
81 | advancedCardBuilder.addItem(new MyCustomItem.Builder()
82 | .text("Custom Item")
83 | .icon(new IconicsDrawable(c)
84 | .icon(CommunityMaterial.Icon.cmd_code_braces)
85 | .sizeDp(18))
86 | .build());
87 |
88 | advancedCardBuilder.addItem(createDynamicItem("Tap for a random number & swap position", c));
89 |
90 | MaterialAboutCard.Builder customAdapterCardBuilder = new MaterialAboutCard.Builder();
91 | // Create list of libraries
92 | List libraries = new ArrayList<>();
93 |
94 | // Add libraries that are hosted on GitHub with an Apache v2 license.
95 | libraries.add(Licenses.fromGitHubApacheV2("yshrsmz/LicenseAdapter"));
96 | libraries.add(Licenses.fromGitHubApacheV2("daniel-stoneuk/material-about-library"));
97 |
98 | customAdapterCardBuilder.title("Custom Adapter (License Adapter)");
99 | customAdapterCardBuilder.customAdapter(new LicenseAdapter(libraries));
100 |
101 | return Demo.createMaterialAboutList(c, getIntent().getIntExtra(THEME_EXTRA, THEME_LIGHT)).addCard(advancedCardBuilder.build()).addCard(customAdapterCardBuilder.build());
102 | }
103 |
104 | private MaterialAboutActionItem createDynamicItem(String subText, final Context c) {
105 | final MaterialAboutActionItem item = new MaterialAboutActionItem.Builder()
106 | .text("Dynamic UI")
107 | .subText(subText)
108 | .icon(new IconicsDrawable(c)
109 | .icon(CommunityMaterial.Icon.cmd_refresh)
110 | .sizeDp(18))
111 | .build();
112 | item.setOnClickAction(new MaterialAboutItemOnClickAction() {
113 | @Override
114 | public void onClick() {
115 | getList().getCards().get(4).getItems().remove(getList().getCards().get(4).getItems().indexOf(item));
116 | int newIndex = ((int) (Math.random() * 5));
117 | getList().getCards().get(4).getItems().add(newIndex, item);
118 | item.setSubText("Random number: " + ((int) (Math.random() * 10)));
119 | setMaterialAboutList(getList());
120 | }
121 | });
122 |
123 | return item;
124 | }
125 |
126 |
127 | @Override
128 | protected void onCreate(@Nullable Bundle savedInstanceState) {
129 | switch (getIntent().getIntExtra(THEME_EXTRA, THEME_LIGHT)) {
130 | case THEME_LIGHT:
131 | setTheme(R.style.AppTheme_MaterialAboutActivity_Light);
132 | break;
133 | case THEME_DARK:
134 | setTheme(R.style.AppTheme_MaterialAboutActivity_Dark);
135 | break;
136 | case THEME_DAYNIGHT:
137 | setTheme(R.style.AppTheme_MaterialAboutActivity_DayNight);
138 | break;
139 | case THEME_CUSTOM_CARDVIEW:
140 | setTheme(R.style.AppTheme_MaterialAboutActivity_Light_DarkActionBar_CustomCardView);
141 | break;
142 | }
143 |
144 | super.onCreate(savedInstanceState);
145 |
146 | // Call this method to let the scrollbar scroll off screen
147 | // setScrollToolbar(true);
148 | }
149 |
150 | @Override
151 | protected CharSequence getActivityTitle() {
152 | return getString(R.string.mal_title_about);
153 | }
154 |
155 | @NonNull
156 | @Override
157 | protected ViewTypeManager getViewTypeManager() {
158 | return new MyViewTypeManager();
159 | }
160 |
161 | @Override
162 | public boolean onCreateOptionsMenu(Menu menu) {
163 | super.onCreateOptionsMenu(menu);
164 | getMenuInflater().inflate(R.menu.menu_example_material_about, menu);
165 | return true;
166 | }
167 |
168 | @Override
169 | public boolean onOptionsItemSelected(MenuItem item) {
170 | if (item.getItemId() == R.id.action_refresh) {
171 | refreshMaterialAboutList();
172 | return true;
173 | }
174 | return super.onOptionsItemSelected(item);
175 | }
176 | }
177 |
--------------------------------------------------------------------------------
/app/src/main/java/com/danielstone/materialaboutlibrarydemo/ExampleMaterialAboutFragment.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrarydemo;
2 |
3 | import android.content.Context;
4 | import android.os.Handler;
5 | import androidx.core.content.ContextCompat;
6 | import android.util.Log;
7 |
8 | import com.danielstone.materialaboutlibrary.MaterialAboutFragment;
9 | import com.danielstone.materialaboutlibrary.items.MaterialAboutActionItem;
10 | import com.danielstone.materialaboutlibrary.items.MaterialAboutItemOnClickAction;
11 | import com.danielstone.materialaboutlibrary.model.MaterialAboutList;
12 | import com.mikepenz.community_material_typeface_library.CommunityMaterial;
13 | import com.mikepenz.iconics.IconicsDrawable;
14 |
15 | import static com.danielstone.materialaboutlibrarydemo.ExampleMaterialAboutActivity.THEME_LIGHT;
16 |
17 |
18 | public class ExampleMaterialAboutFragment extends MaterialAboutFragment {
19 |
20 | private MaterialAboutActionItem createDynamicItem(String subText, final Context c) {
21 | final MaterialAboutActionItem item = new MaterialAboutActionItem.Builder()
22 | .text("Dynamic UI")
23 | .subText(subText)
24 | .icon(new IconicsDrawable(c)
25 | .icon(CommunityMaterial.Icon.cmd_refresh)
26 | .sizeDp(18))
27 | .build();
28 | item.setOnClickAction(new MaterialAboutItemOnClickAction() {
29 | @Override
30 | public void onClick() {
31 | item.setSubText("Random number: " + ((int) (Math.random() * 10)));
32 | refreshMaterialAboutList();
33 | }
34 | });
35 | return item;
36 |
37 | }
38 |
39 | @Override
40 | protected MaterialAboutList getMaterialAboutList(final Context c) {
41 | MaterialAboutList list = Demo.createMaterialAboutList(c, THEME_LIGHT);
42 |
43 | list.getCards().get(2).getItems().add(createDynamicItem("Tap for a random number", c));
44 |
45 | final MaterialAboutActionItem time = new MaterialAboutActionItem.Builder()
46 | .text("Unix Time In Millis")
47 | .subText("Time")
48 | .icon(new IconicsDrawable(c)
49 | .icon(CommunityMaterial.Icon.cmd_clock)
50 | .sizeDp(18))
51 | .build();
52 | list.getCards().get(2).getItems().add(time);
53 |
54 | return list;
55 | }
56 |
57 | final Handler handler = new Handler();
58 | Runnable runnable = new Runnable() {
59 | @Override
60 | public void run() {
61 | Log.i("MaterialAboutFragment", "Updating with time");
62 | if (getList().getCards().size() > 0) {
63 | ((MaterialAboutActionItem) getList().getCards().get(2).getItems().get(7)).setSubText("" + System.currentTimeMillis());
64 | refreshMaterialAboutList();
65 | }
66 | handler.postDelayed(this, 1000);
67 | }
68 | };
69 |
70 |
71 | @Override
72 | public void onResume() {
73 | super.onResume();
74 | runnable.run();
75 | }
76 |
77 | @Override
78 | public void onPause() {
79 | super.onPause();
80 | handler.removeCallbacks(runnable);
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/app/src/main/java/com/danielstone/materialaboutlibrarydemo/ExampleMaterialAboutFragmentActivity.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrarydemo;
2 |
3 | import android.os.Bundle;
4 | import androidx.core.app.NavUtils;
5 | import androidx.appcompat.app.ActionBar;
6 | import androidx.appcompat.app.AppCompatActivity;
7 | import androidx.appcompat.widget.Toolbar;
8 |
9 | public class ExampleMaterialAboutFragmentActivity extends AppCompatActivity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_example_material_about_fragment);
15 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
16 | setSupportActionBar(toolbar);
17 | getSupportFragmentManager().beginTransaction()
18 | .replace(R.id.container, ExampleMaterialAboutFragment.newInstance(new ExampleMaterialAboutFragment()))
19 | .commit();
20 |
21 | setTitle("About Fragment Activity");
22 |
23 | if (NavUtils.getParentActivityName(this) != null) {
24 | ActionBar actionBar = getSupportActionBar();
25 | if (actionBar != null) {
26 | actionBar.setDisplayHomeAsUpEnabled(true);
27 | }
28 | }
29 |
30 | }
31 |
32 |
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/danielstone/materialaboutlibrarydemo/ExampleMaterialAboutLicenseActivity.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrarydemo;
2 |
3 | import android.content.Context;
4 | import androidx.annotation.NonNull;
5 | import android.view.MenuItem;
6 |
7 | import com.danielstone.materialaboutlibrary.model.MaterialAboutList;
8 |
9 | public class ExampleMaterialAboutLicenseActivity extends ExampleMaterialAboutActivity {
10 |
11 | @NonNull @Override
12 | protected MaterialAboutList getMaterialAboutList(@NonNull final Context c) {
13 | return Demo.createMaterialAboutLicenseList(c);
14 | }
15 |
16 | @Override
17 | protected CharSequence getActivityTitle() {
18 | return getString(R.string.mal_title_licenses);
19 | }
20 |
21 | @Override
22 | public boolean onOptionsItemSelected(MenuItem item) {
23 | switch (item.getItemId()) {
24 | case android.R.id.home:
25 | finish();
26 | return true;
27 | default:
28 | return false;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/danielstone/materialaboutlibrarydemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrarydemo;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import androidx.appcompat.app.AppCompatActivity;
6 | import androidx.appcompat.widget.Toolbar;
7 | import android.view.Menu;
8 | import android.view.MenuItem;
9 | import android.view.View;
10 | import android.widget.Button;
11 |
12 | public class MainActivity extends AppCompatActivity {
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_main);
18 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
19 | setSupportActionBar(toolbar);
20 |
21 | Button fragmentButton = (Button) findViewById(R.id.fragment_button);
22 | fragmentButton.setOnClickListener(new View.OnClickListener() {
23 | @Override
24 | public void onClick(View v) {
25 | Intent i = new Intent(MainActivity.this, ExampleMaterialAboutFragmentActivity.class);
26 | startActivity(i);
27 | }
28 | });
29 |
30 | }
31 |
32 | public void onActivityButtonPressed(View view) {
33 | Intent i = new Intent(MainActivity.this, ExampleMaterialAboutActivity.class);
34 | i.putExtra(ExampleMaterialAboutActivity.THEME_EXTRA, Integer.parseInt(view.getTag().toString()));
35 | startActivity(i);
36 | }
37 |
38 | @Override
39 | public boolean onCreateOptionsMenu(Menu menu) {
40 | // Inflate the menu; this adds items to the action bar if it is present.
41 | getMenuInflater().inflate(R.menu.menu_main, menu);
42 | return true;
43 | }
44 |
45 | @Override
46 | public boolean onOptionsItemSelected(MenuItem item) {
47 | // Handle action bar item clicks here. The action bar will
48 | // automatically handle clicks on the Home/Up button, so long
49 | // as you specify a parent activity in AndroidManifest.xml.
50 | int id = item.getItemId();
51 |
52 | //noinspection SimplifiableIfStatement
53 | if (id == R.id.action_settings) {
54 | Intent i = new Intent(this, ExampleMaterialAboutActivity.class);
55 | startActivity(i);
56 | return true;
57 | }
58 |
59 | return super.onOptionsItemSelected(item);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/danielstone/materialaboutlibrarydemo/custom/MyCustomItem.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrarydemo.custom;
2 |
3 | import android.content.Context;
4 | import android.graphics.drawable.Drawable;
5 | import android.os.Build;
6 | import androidx.annotation.DrawableRes;
7 | import androidx.annotation.IntDef;
8 | import androidx.annotation.StringRes;
9 | import android.text.Html;
10 | import android.util.TypedValue;
11 | import android.view.Gravity;
12 | import android.view.View;
13 | import android.widget.ImageView;
14 | import android.widget.LinearLayout;
15 | import android.widget.TextView;
16 |
17 | import com.danielstone.materialaboutlibrary.R;
18 | import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder;
19 | import com.danielstone.materialaboutlibrary.items.MaterialAboutItem;
20 |
21 | import java.lang.annotation.Retention;
22 | import java.lang.annotation.RetentionPolicy;
23 |
24 | import static android.view.View.GONE;
25 |
26 | public class MyCustomItem extends MaterialAboutItem {
27 |
28 | public interface OnClickListener {
29 | void onClick();
30 | }
31 |
32 |
33 |
34 | @Retention(RetentionPolicy.SOURCE)
35 | @IntDef({GRAVITY_TOP, GRAVITY_MIDDLE, GRAVITY_BOTTOM})
36 | public @interface IconGravity {
37 | }
38 |
39 | public static final int GRAVITY_TOP = 0;
40 | public static final int GRAVITY_MIDDLE = 1;
41 | public static final int GRAVITY_BOTTOM = 2;
42 |
43 |
44 | private CharSequence text = null;
45 | private int textRes = 0;
46 |
47 | private CharSequence subText = null;
48 | private int subTextRes = 0;
49 |
50 | private Drawable icon = null;
51 | private int iconRes = 0;
52 | private boolean showIcon = true;
53 | private int iconGravity = GRAVITY_MIDDLE;
54 |
55 | private MyCustomItem.OnClickListener onClickListener = null;
56 |
57 | @Override
58 | public int getType() {
59 | return MyViewTypeManager.ItemType.CUSTOM_ITEM;
60 | }
61 |
62 | @Override
63 | public String getDetailString() {
64 | return "MyCustomItem{" +
65 | "text=" + text +
66 | ", textRes=" + textRes +
67 | ", subText=" + subText +
68 | ", subTextRes=" + subTextRes +
69 | ", icon=" + icon +
70 | ", iconRes=" + iconRes +
71 | ", showIcon=" + showIcon +
72 | ", iconGravity=" + iconGravity +
73 | ", onClickListener=" + onClickListener +
74 | '}';
75 | }
76 |
77 | public MyCustomItem(MyCustomItem item) {
78 | this.id = item.getId();
79 | this.text = item.getText();
80 | this.textRes = item.getTextRes();
81 | this.subText = item.getSubText();
82 | this.subTextRes = item.getSubTextRes();
83 | this.icon = item.getIcon();
84 | this.iconRes = item.getIconRes();
85 | this.showIcon = item.shouldShowIcon();
86 | this.iconGravity = item.getIconGravity();
87 | this.onClickListener = item.getOnClickListener();
88 | }
89 |
90 | @Override
91 | public MyCustomItem clone() {
92 | return new MyCustomItem(this);
93 | }
94 |
95 | public static MaterialAboutItemViewHolder getViewHolder(View view) {
96 | return new MyCustomItemViewHolder(view);
97 | }
98 |
99 | public static class MyCustomItemViewHolder extends MaterialAboutItemViewHolder implements View.OnClickListener {
100 | public final View view;
101 | public final ImageView icon;
102 | public final TextView text;
103 | public final TextView subText;
104 | public MyCustomItem.OnClickListener onClickListener;
105 |
106 | MyCustomItemViewHolder(View view) {
107 | super(view);
108 | this.view = view;
109 | icon = (ImageView) view.findViewById(R.id.mal_item_image);
110 | text = (TextView) view.findViewById(R.id.mal_item_text);
111 | subText = (TextView) view.findViewById(R.id.mal_action_item_subtext);
112 |
113 | view.setOnClickListener(this);
114 | onClickListener = null;
115 | }
116 |
117 | @Override
118 | public void onClick(View v) {
119 | if (onClickListener != null) {
120 | onClickListener.onClick();
121 | }
122 | }
123 | }
124 |
125 | private MyCustomItem(Builder builder) {
126 | this.text = builder.text;
127 | this.textRes = builder.textRes;
128 |
129 | this.subText = builder.subText;
130 | this.subTextRes = builder.subTextRes;
131 |
132 | this.icon = builder.icon;
133 | this.iconRes = builder.iconRes;
134 |
135 | this.showIcon = builder.showIcon;
136 |
137 | this.iconGravity = builder.iconGravity;
138 |
139 | this.onClickListener = builder.onClickListener;
140 | }
141 |
142 | public MyCustomItem(CharSequence text, CharSequence subText, Drawable icon, OnClickListener onClickListener) {
143 | this.text = text;
144 | this.subText = subText;
145 | this.icon = icon;
146 | this.onClickListener = onClickListener;
147 | }
148 |
149 | public MyCustomItem(CharSequence text, CharSequence subText, Drawable icon) {
150 | this.text = text;
151 | this.subText = subText;
152 | this.icon = icon;
153 | }
154 |
155 | public MyCustomItem(int textRes, int subTextRes, int iconRes, OnClickListener onClickListener) {
156 | this.textRes = textRes;
157 | this.subTextRes = subTextRes;
158 | this.iconRes = iconRes;
159 | this.onClickListener = onClickListener;
160 | }
161 |
162 | public MyCustomItem(int textRes, int subTextRes, int iconRes) {
163 | this.textRes = textRes;
164 | this.subTextRes = subTextRes;
165 | this.iconRes = iconRes;
166 | }
167 |
168 | public CharSequence getText() {
169 | return text;
170 | }
171 |
172 | public int getTextRes() {
173 | return textRes;
174 | }
175 |
176 | public CharSequence getSubText() {
177 | return subText;
178 | }
179 |
180 | public int getSubTextRes() {
181 | return subTextRes;
182 | }
183 |
184 | public Drawable getIcon() {
185 | return icon;
186 | }
187 |
188 | public int getIconRes() {
189 | return iconRes;
190 | }
191 |
192 | public boolean shouldShowIcon() {
193 | return showIcon;
194 | }
195 |
196 | @IconGravity
197 | public int getIconGravity() {
198 | return iconGravity;
199 | }
200 |
201 | public MyCustomItem.OnClickListener getOnClickListener() {
202 | return onClickListener;
203 | }
204 |
205 | public static void setupItem(MyCustomItemViewHolder holder, MyCustomItem item, Context context) {
206 | CharSequence text = item.getText();
207 | int textRes = item.getTextRes();
208 |
209 | holder.text.setVisibility(View.VISIBLE);
210 | if (text != null) {
211 | holder.text.setText(text);
212 | } else if (textRes != 0) {
213 | holder.text.setText(textRes);
214 | } else {
215 | holder.text.setVisibility(GONE);
216 | }
217 |
218 | CharSequence subText = item.getSubText();
219 | int subTextRes = item.getSubTextRes();
220 |
221 | holder.subText.setVisibility(View.VISIBLE);
222 | if (subText != null) {
223 | holder.subText.setText(subText);
224 | } else if (subTextRes != 0) {
225 | holder.subText.setText(subTextRes);
226 | } else {
227 | holder.subText.setVisibility(GONE);
228 | }
229 |
230 | if (item.shouldShowIcon()) {
231 | holder.icon.setVisibility(View.VISIBLE);
232 | Drawable drawable = item.getIcon();
233 | int drawableRes = item.getIconRes();
234 | if (drawable != null) {
235 | holder.icon.setImageDrawable(drawable);
236 | } else if (drawableRes != 0) {
237 | holder.icon.setImageResource(drawableRes);
238 | }
239 | } else {
240 | holder.icon.setVisibility(GONE);
241 | }
242 |
243 | LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) holder.icon.getLayoutParams();
244 | switch (item.getIconGravity()) {
245 | case MyCustomItem.GRAVITY_TOP:
246 | params.gravity = Gravity.TOP;
247 | break;
248 | case MyCustomItem.GRAVITY_MIDDLE:
249 | params.gravity = Gravity.CENTER_VERTICAL;
250 | break;
251 | case MyCustomItem.GRAVITY_BOTTOM:
252 | params.gravity = Gravity.BOTTOM;
253 | break;
254 | }
255 | holder.icon.setLayoutParams(params);
256 |
257 | int pL = 0, pT = 0, pR = 0, pB = 0;
258 | if (Build.VERSION.SDK_INT < 21) {
259 | pL = holder.view.getPaddingLeft();
260 | pT = holder.view.getPaddingTop();
261 | pR = holder.view.getPaddingRight();
262 | pB = holder.view.getPaddingBottom();
263 | }
264 |
265 | if (item.getOnClickListener() != null) {
266 | TypedValue outValue = new TypedValue();
267 | context.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true);
268 | holder.view.setBackgroundResource(outValue.resourceId);
269 | holder.onClickListener = item.getOnClickListener();
270 | holder.view.setSoundEffectsEnabled(true);
271 | } else {
272 | TypedValue outValue = new TypedValue();
273 | context.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, false);
274 | holder.view.setBackgroundResource(outValue.resourceId);
275 | holder.onClickListener = null;
276 | holder.view.setSoundEffectsEnabled(false);
277 | }
278 |
279 | if (Build.VERSION.SDK_INT < 21) {
280 | holder.view.setPadding(pL, pT, pR, pB);
281 | }
282 | }
283 |
284 | public static class Builder {
285 |
286 | private CharSequence text = null;
287 | @StringRes
288 | private int textRes = 0;
289 |
290 | private CharSequence subText = null;
291 | @StringRes
292 | private int subTextRes = 0;
293 |
294 | private Drawable icon = null;
295 | @DrawableRes
296 | private int iconRes = 0;
297 |
298 | private boolean showIcon = true;
299 |
300 | @IconGravity
301 | private int iconGravity = GRAVITY_MIDDLE;
302 |
303 | MyCustomItem.OnClickListener onClickListener;
304 |
305 | public Builder text(CharSequence text) {
306 | this.text = text;
307 | this.textRes = 0;
308 | return this;
309 | }
310 |
311 | public Builder text(@StringRes int text) {
312 | this.textRes = text;
313 | this.text = null;
314 | return this;
315 | }
316 |
317 | public Builder subText(CharSequence subText) {
318 | this.subText = subText;
319 | this.subTextRes = 0;
320 | return this;
321 | }
322 |
323 | public Builder subText(@StringRes int subTextRes) {
324 | this.subText = null;
325 | this.subTextRes = subTextRes;
326 | return this;
327 | }
328 |
329 | public Builder subTextHtml(String subTextHtml) {
330 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
331 | this.subText = Html.fromHtml(subTextHtml, Html.FROM_HTML_MODE_LEGACY);
332 | } else {
333 | //noinspection deprecation
334 | this.subText = Html.fromHtml(subTextHtml);
335 | }
336 | this.subTextRes = 0;
337 | return this;
338 | }
339 |
340 | public Builder icon(Drawable icon) {
341 | this.icon = icon;
342 | this.iconRes = 0;
343 | return this;
344 | }
345 |
346 | public Builder icon(@DrawableRes int iconRes) {
347 | this.icon = null;
348 | this.iconRes = iconRes;
349 | return this;
350 | }
351 |
352 | public Builder showIcon(boolean showIcon) {
353 | this.showIcon = showIcon;
354 | return this;
355 | }
356 |
357 | public Builder setIconGravity(@IconGravity int iconGravity) {
358 | this.iconGravity = iconGravity;
359 | return this;
360 | }
361 |
362 | public Builder setOnClickListener(MyCustomItem.OnClickListener onClickListener) {
363 | this.onClickListener = onClickListener;
364 | return this;
365 | }
366 |
367 | public MyCustomItem build() {
368 | return new MyCustomItem(this);
369 | }
370 | }
371 | }
372 |
--------------------------------------------------------------------------------
/app/src/main/java/com/danielstone/materialaboutlibrarydemo/custom/MyViewTypeManager.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrarydemo.custom;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder;
7 | import com.danielstone.materialaboutlibrary.items.MaterialAboutActionItem;
8 | import com.danielstone.materialaboutlibrary.items.MaterialAboutItem;
9 | import com.danielstone.materialaboutlibrary.items.MaterialAboutTitleItem;
10 | import com.danielstone.materialaboutlibrary.util.ViewTypeManager;
11 | import com.danielstone.materialaboutlibrarydemo.R;
12 |
13 | import static com.danielstone.materialaboutlibrarydemo.custom.MyViewTypeManager.ItemLayout.*;
14 | import static com.danielstone.materialaboutlibrarydemo.custom.MyViewTypeManager.ItemType.*;
15 |
16 | public class MyViewTypeManager extends ViewTypeManager {
17 |
18 | public static final class ItemType {
19 | public static final int ACTION_ITEM = ViewTypeManager.ItemType.ACTION_ITEM;
20 | public static final int TITLE_ITEM = ViewTypeManager.ItemType.TITLE_ITEM;
21 | public static final int CUSTOM_ITEM = 10;
22 | }
23 |
24 | public static final class ItemLayout {
25 | public static final int ACTION_LAYOUT = ViewTypeManager.ItemLayout.ACTION_LAYOUT;
26 | public static final int TITLE_LAYOUT = ViewTypeManager.ItemLayout.TITLE_LAYOUT;
27 | public static final int CUSTOM_LAYOUT = R.layout.custom_item;
28 | }
29 |
30 |
31 | public int getLayout(int itemType) {
32 | switch (itemType) {
33 | case ACTION_ITEM:
34 | return ACTION_LAYOUT;
35 | case TITLE_ITEM:
36 | return TITLE_LAYOUT;
37 | case CUSTOM_ITEM:
38 | return CUSTOM_LAYOUT;
39 | default:
40 | return -1;
41 | }
42 | }
43 |
44 | public MaterialAboutItemViewHolder getViewHolder(int itemType, View view) {
45 | switch (itemType) {
46 | case ACTION_ITEM:
47 | return MaterialAboutActionItem.getViewHolder(view);
48 | case TITLE_ITEM:
49 | return MaterialAboutTitleItem.getViewHolder(view);
50 | case CUSTOM_ITEM:
51 | return MyCustomItem.getViewHolder(view);
52 | default:
53 | return null;
54 | }
55 | }
56 |
57 | public void setupItem(int itemType, MaterialAboutItemViewHolder holder, MaterialAboutItem item, Context context) {
58 | switch (itemType) {
59 | case ACTION_ITEM:
60 | MaterialAboutActionItem.setupItem((MaterialAboutActionItem.MaterialAboutActionItemViewHolder) holder, (MaterialAboutActionItem) item, context);
61 | break;
62 | case TITLE_ITEM:
63 | MaterialAboutTitleItem.setupItem((MaterialAboutTitleItem.MaterialAboutTitleItemViewHolder) holder, (MaterialAboutTitleItem) item, context);
64 | break;
65 | case CUSTOM_ITEM:
66 | MyCustomItem.setupItem((MyCustomItem.MyCustomItemViewHolder) holder, (MyCustomItem) item, context);
67 | break;
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_example_material_about_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_example_material_about_fragment.xml:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
21 |
22 |
30 |
31 |
39 |
40 |
48 |
49 |
57 |
58 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/custom_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
21 |
22 |
28 |
29 |
35 |
36 |
37 |
38 |
51 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/mal_material_about_action_item_overridefornoicons.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
32 |
33 |
39 |
40 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/mal_material_about_list_card_overrideforlistlayout.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
24 |
25 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_example_material_about.xml:
--------------------------------------------------------------------------------
1 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #FFFFFF
8 | #9E9E9E
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Material About Library Demo
3 | About
4 | Refresh
5 | ExampleMaterialAboutFragment
6 |
7 | Settings
8 | Launch About Activity
9 | Launch About Fragment
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
14 |
15 |
20 |
21 |
22 |
27 |
28 |
33 |
34 |
43 |
44 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_descriptor.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/web_hi_res_512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/app/src/main/web_hi_res_512.png
--------------------------------------------------------------------------------
/app/src/test/java/com/danielstone/materialaboutlibrarydemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrarydemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/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 | google()
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.6.2'
10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' // Add this line
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | google()
20 | jcenter()
21 | }
22 | }
23 |
24 | ext {
25 | compileSdkVersion = 29
26 | targetSdkVersion = compileSdkVersion
27 | minSdkVersion = 14
28 |
29 | appCompatVersion = '1.1.0'
30 | materialVersion = '1.1.0'
31 | }
32 |
33 | task clean(type: Delete) {
34 | delete rootProject.buildDir
35 | }
36 |
--------------------------------------------------------------------------------
/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 | android.enableJetifier=true
13 | android.useAndroidX=true
14 | org.gradle.jvmargs=-Xmx1536m
15 |
16 | # When configured, Gradle will run in incubating parallel mode.
17 | # This option should only be used with decoupled projects. More details, visit
18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
19 | # org.gradle.parallel=true
20 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Mar 05 16:12:34 MSK 2020
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-5.6.4-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 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 |
4 | group = 'com.github.daniel-stoneuk'
5 |
6 | def versionMajor = 3
7 | def versionMinor = 1
8 | def versionPatch = 2
9 | def versionBuild = 0 // bump for dogfood builds, public betas, etc.
10 |
11 | android {
12 | compileSdkVersion rootProject.ext.compileSdkVersion
13 |
14 | defaultConfig {
15 | minSdkVersion rootProject.ext.minSdkVersion
16 | targetSdkVersion rootProject.ext.targetSdkVersion
17 | versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
18 | versionName "${versionMajor}.${versionMinor}" + (versionPatch == 0 ? "" : ".${versionPatch}")
19 | }
20 |
21 | buildTypes {
22 | release {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
25 | }
26 | }
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(dir: 'libs', include: ['*.jar'])
31 | implementation "androidx.appcompat:appcompat:$appCompatVersion"
32 | implementation "com.google.android.material:material:$materialVersion"
33 | }
34 |
--------------------------------------------------------------------------------
/library/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 /Users/danielstone/Library/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/java/com/danielstone/materialaboutlibrary/ConvenienceBuilder.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrary;
2 |
3 | import android.content.ActivityNotFoundException;
4 | import android.content.Context;
5 | import android.content.DialogInterface;
6 | import android.content.Intent;
7 | import android.content.pm.ApplicationInfo;
8 | import android.content.pm.PackageInfo;
9 | import android.content.pm.PackageManager;
10 | import android.graphics.drawable.Drawable;
11 | import android.net.Uri;
12 | import android.os.Build;
13 | import androidx.annotation.Nullable;
14 | import androidx.appcompat.app.AlertDialog;
15 | import android.webkit.WebView;
16 | import android.widget.Toast;
17 |
18 | import com.danielstone.materialaboutlibrary.items.MaterialAboutActionItem;
19 | import com.danielstone.materialaboutlibrary.items.MaterialAboutItemOnClickAction;
20 | import com.danielstone.materialaboutlibrary.items.MaterialAboutTitleItem;
21 | import com.danielstone.materialaboutlibrary.model.MaterialAboutCard;
22 | import com.danielstone.materialaboutlibrary.util.OpenSourceLicense;
23 |
24 | @SuppressWarnings("JavaDoc")
25 | public class ConvenienceBuilder {
26 |
27 | public static MaterialAboutTitleItem createAppTitleItem(String appName, Drawable applicationIcon) {
28 | return new MaterialAboutTitleItem(appName, null, applicationIcon);
29 | }
30 |
31 | public static MaterialAboutTitleItem createAppTitleItem(Context c) {
32 | Context applicationContext = c.getApplicationContext();
33 | PackageManager packageManager = applicationContext.getPackageManager();
34 | ApplicationInfo applicationInfo = applicationContext.getApplicationInfo();
35 | CharSequence appName = packageManager.getApplicationLabel(applicationInfo);
36 | Drawable applicationIcon = packageManager.getApplicationIcon(applicationInfo);
37 | return createAppTitleItem(appName == null ? "" : appName.toString(), applicationIcon);
38 | }
39 |
40 | /**
41 | * Creates an item with version info read from the PackageManager for current application.
42 | *
43 | * @param c context
44 | * @param icon
45 | * @param text
46 | * @param includeVersionCode
47 | * @return Item to add to card.
48 | */
49 | public static MaterialAboutActionItem createVersionActionItem(Context c, Drawable icon, CharSequence text, boolean includeVersionCode) {
50 | String versionName = "";
51 | int versionCode = 0;
52 | try {
53 | PackageInfo pInfo = c.getPackageManager().getPackageInfo(c.getPackageName(), 0);
54 | versionName = pInfo.versionName;
55 | versionCode = pInfo.versionCode;
56 | } catch (PackageManager.NameNotFoundException ignored) {
57 | // This shouldn't happen.
58 | }
59 | return new MaterialAboutActionItem.Builder()
60 | .text(text)
61 | .subText(versionName + (includeVersionCode ? " (" + versionCode + ")" : ""))
62 | .icon(icon)
63 | .build();
64 | }
65 |
66 | public static MaterialAboutItemOnClickAction createWebViewDialogOnClickAction(final Context c, final CharSequence dialogTitle, final String htmlString, final boolean isStringUrl, final boolean supportZoom) {
67 | return createWebViewDialogOnClickAction(c, dialogTitle, c.getString(R.string.mal_close), htmlString, isStringUrl, supportZoom);
68 | }
69 |
70 | public static MaterialAboutItemOnClickAction createWebViewDialogOnClickAction(final Context c, final CharSequence dialogTitle, final CharSequence dialogNegativeButton, final String htmlString, final boolean isStringUrl, final boolean supportZoom) {
71 |
72 | return new MaterialAboutItemOnClickAction() {
73 | @Override
74 | public void onClick() {
75 | AlertDialog.Builder alertBuilder = new AlertDialog.Builder(c);
76 | alertBuilder.setTitle(dialogTitle);
77 |
78 | final WebView wv = new WebView(c);
79 | wv.getSettings().setSupportZoom(supportZoom);
80 | if (!supportZoom) {
81 | wv.getSettings().setLoadWithOverviewMode(true);
82 | wv.getSettings().setUseWideViewPort(true);
83 | }
84 | if (isStringUrl) {
85 | wv.loadUrl(htmlString);
86 | } else {
87 | wv.loadData(htmlString, "text/html; charset=utf-8", "UTF-8");
88 | }
89 |
90 | alertBuilder.setView(wv);
91 | alertBuilder.setNegativeButton(dialogNegativeButton, new DialogInterface.OnClickListener() {
92 | @Override
93 | public void onClick(DialogInterface dialog, int id) {
94 | wv.destroy();
95 | dialog.dismiss();
96 | }
97 | });
98 |
99 | final AlertDialog dialog = alertBuilder.create();
100 | dialog.show();
101 | }
102 | };
103 | }
104 |
105 |
106 | public static MaterialAboutActionItem createWebViewDialogItem(Context c, Drawable icon, CharSequence text, @Nullable CharSequence subText, CharSequence dialogTitle, String htmlString, boolean isStringUrl, boolean supportZoom) {
107 | return createWebViewDialogItem(c, icon, text, subText, dialogTitle, c.getString(R.string.mal_close), htmlString, isStringUrl, supportZoom);
108 | }
109 |
110 | public static MaterialAboutActionItem createWebViewDialogItem(Context c, Drawable icon, CharSequence text, @Nullable CharSequence subText, CharSequence dialogTitle, CharSequence dialogNegativeButton, String htmlString, boolean isStringUrl, boolean supportZoom) {
111 | return new MaterialAboutActionItem.Builder()
112 | .text(text)
113 | .subText(subText)
114 | .icon(icon)
115 | .setOnClickAction(createWebViewDialogOnClickAction(c, dialogTitle, dialogNegativeButton, htmlString, isStringUrl, supportZoom))
116 | .build();
117 | }
118 |
119 |
120 | public static MaterialAboutItemOnClickAction createWebsiteOnClickAction(final Context c, final Uri websiteUrl) {
121 | return new MaterialAboutItemOnClickAction() {
122 | @Override
123 | public void onClick() {
124 | Intent i = new Intent(Intent.ACTION_VIEW);
125 | i.setData(websiteUrl);
126 | try {
127 | c.startActivity(i);
128 | } catch (Exception e) {
129 | // No activity to handle intent
130 | Toast.makeText(c, R.string.mal_activity_exception, Toast.LENGTH_SHORT).show();
131 | }
132 | }
133 | };
134 | }
135 |
136 | /**
137 | * Creates an ActionItem which will open a url when tapped
138 | *
139 | * @param c context
140 | * @param text
141 | * @param icon
142 | * @param websiteUrl (subText)
143 | * @return Item to add to card.
144 | */
145 | public static MaterialAboutActionItem createWebsiteActionItem(Context c, Drawable icon, CharSequence text, boolean showAddress, final Uri websiteUrl) {
146 | return new MaterialAboutActionItem.Builder()
147 | .text(text)
148 | .subText((showAddress ? websiteUrl.toString() : null))
149 | .icon(icon)
150 | .setOnClickAction(createWebsiteOnClickAction(c, websiteUrl))
151 | .build();
152 | }
153 |
154 | /**
155 | * Creates a MaterialAboutItemOnClickAction that will open
156 | * the Google Play store listing for the app.
157 | *
158 | * @param c context
159 | * @return onClickAction
160 | */
161 | public static MaterialAboutItemOnClickAction createRateOnClickAction(final Context c) {
162 | Uri uri = Uri.parse("market://details?id=" + c.getPackageName());
163 | final Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
164 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
165 | goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
166 | Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
167 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
168 | } else {
169 | goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
170 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
171 | }
172 |
173 | return new MaterialAboutItemOnClickAction() {
174 | @Override
175 | public void onClick() {
176 | try {
177 | c.startActivity(goToMarket);
178 | } catch (ActivityNotFoundException e) {
179 | c.startActivity(new Intent(Intent.ACTION_VIEW,
180 | Uri.parse("http://play.google.com/store/apps/details?id=" + c.getPackageName())));
181 | }
182 | }
183 | };
184 | }
185 |
186 | /**
187 | * Creates an ActionItem which will open the play store when tapped
188 | *
189 | * @param c context
190 | * @param text
191 | * @param subText
192 | * @param icon
193 | * @return Item to add to card.
194 | */
195 | public static MaterialAboutActionItem createRateActionItem(Context c, Drawable icon, CharSequence text, @Nullable CharSequence subText) {
196 |
197 | return new MaterialAboutActionItem.Builder()
198 | .text(text)
199 | .subText(subText)
200 | .icon(icon)
201 | .setOnClickAction(createRateOnClickAction(c))
202 | .build();
203 | }
204 |
205 | public static MaterialAboutItemOnClickAction createEmailOnClickAction(final Context c, String email, String emailSubject) {
206 | return createEmailOnClickAction(c, email, emailSubject, c.getString(R.string.mal_send_email));
207 | }
208 |
209 | /**
210 | * Creates a MaterialAboutItemOnClickAction that will open
211 | * an email intent with specified address.
212 | *
213 | * @param c context
214 | * @param email email address
215 | * @return onClickAction
216 | */
217 | public static MaterialAboutItemOnClickAction createEmailOnClickAction(final Context c, String email, String emailSubject, final CharSequence chooserTitle) {
218 |
219 | final Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + email));
220 | emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
221 |
222 | return new MaterialAboutItemOnClickAction() {
223 | @Override
224 | public void onClick() {
225 | try {
226 | c.startActivity(Intent.createChooser(emailIntent, chooserTitle));
227 | } catch (Exception e) {
228 | // No activity to handle intent
229 | Toast.makeText(c, R.string.mal_activity_exception, Toast.LENGTH_SHORT).show();
230 | }
231 | }
232 | };
233 | }
234 |
235 | /**
236 | * Creates an ActionItem which will open the an email intent when tapped
237 | *
238 | * @param c context
239 | * @param text
240 | * @param icon
241 | * @param email email address (also used as subText)
242 | * @return Item to add to card.
243 | */
244 | public static MaterialAboutActionItem createEmailItem(Context c, Drawable icon, CharSequence text, boolean showEmail, String email, String emailSubject, CharSequence chooserTitle) {
245 | return new MaterialAboutActionItem.Builder()
246 | .text(text)
247 | .subText((showEmail ? email : null))
248 | .icon(icon)
249 | .setOnClickAction(createEmailOnClickAction(c, email, emailSubject, chooserTitle))
250 | .build();
251 | }
252 |
253 | public static MaterialAboutActionItem createEmailItem(Context c, Drawable icon, CharSequence text, boolean showEmail, String email, String emailSubject) {
254 | return createEmailItem(c, icon, text, showEmail, email, emailSubject, c.getString(R.string.mal_send_email));
255 | }
256 |
257 | /**
258 | * Creates a MaterialAboutItemOnClickAction that will open
259 | * the dialer with specified number.
260 | *
261 | * @param c context
262 | * @param number phone number
263 | * @return onClickAction
264 | */
265 | public static MaterialAboutItemOnClickAction createPhoneOnClickAction(final Context c, String number) {
266 | final Intent phoneIntent = new Intent(Intent.ACTION_DIAL);
267 | phoneIntent.setData(Uri.parse("tel:" + number));
268 |
269 | return new MaterialAboutItemOnClickAction() {
270 | @Override
271 | public void onClick() {
272 | try {
273 | c.startActivity(phoneIntent);
274 | } catch (Exception e) {
275 | // No activity to handle intent
276 | Toast.makeText(c, R.string.mal_activity_exception, Toast.LENGTH_SHORT).show();
277 | }
278 | }
279 | };
280 | }
281 |
282 | /**
283 | * Creates an ActionItem which will open the dialer when tapped
284 | *
285 | * @param c context
286 | * @param text
287 | * @param icon
288 | * @param number phone number (also used as subText)
289 | * @return Item to add to card.
290 | */
291 | public static MaterialAboutActionItem createPhoneItem(Context c, Drawable icon, CharSequence text, boolean showNumber, String number) {
292 | return new MaterialAboutActionItem.Builder()
293 | .text(text)
294 | .subText((showNumber ? number : null))
295 | .icon(icon)
296 | .setOnClickAction(createPhoneOnClickAction(c, number))
297 | .build();
298 | }
299 |
300 | /**
301 | * Creates a MaterialAboutItemOnClickAction that will open
302 | * maps with a query.
303 | * Query can be either lat,lng(label) or written address
304 | *
305 | * @param c context
306 | * @param addressQuery address query
307 | * @return onClickAction
308 | */
309 | public static MaterialAboutItemOnClickAction createMapOnClickAction(final Context c, String addressQuery) {
310 | final Intent mapIntent = new Intent(Intent.ACTION_VIEW);
311 | mapIntent.setData(Uri.parse("geo:0,0").buildUpon().appendQueryParameter("q", addressQuery).build());
312 | return new MaterialAboutItemOnClickAction() {
313 | @Override
314 | public void onClick() {
315 | try {
316 | c.startActivity(mapIntent);
317 | } catch (Exception e) {
318 | // No activity to handle intent
319 | Toast.makeText(c, R.string.mal_activity_exception, Toast.LENGTH_SHORT).show();
320 | }
321 | }
322 | };
323 | }
324 |
325 | /**
326 | * Creates an ActionItem which will open maps when tapped
327 | * Query can be either lat,lng(label) or written address
328 | *
329 | * @param c context
330 | * @param text
331 | * @param subText can be set to null
332 | * @param icon
333 | * @param addressQuery addressQuery
334 | * @return Item to add to card.
335 | */
336 | public static MaterialAboutActionItem createMapItem(Context c, Drawable icon, CharSequence text, CharSequence subText, String addressQuery) {
337 | return new MaterialAboutActionItem.Builder()
338 | .text(text)
339 | .subText(subText)
340 | .icon(icon)
341 | .setOnClickAction(createMapOnClickAction(c, addressQuery))
342 | .build();
343 | }
344 |
345 | public static MaterialAboutCard createLicenseCard(Context c, Drawable icon, CharSequence libraryTitle, CharSequence year, CharSequence name, OpenSourceLicense license) {
346 |
347 | MaterialAboutActionItem licenseItem = new MaterialAboutActionItem.Builder()
348 | .icon(icon)
349 | .setIconGravity(MaterialAboutActionItem.GRAVITY_TOP)
350 | .text(libraryTitle)
351 | .subText(String.format(c.getString(license.getResourceId()), year, name))
352 | .build();
353 |
354 | return new MaterialAboutCard.Builder().addItem(licenseItem).build();
355 | }
356 |
357 | }
358 |
--------------------------------------------------------------------------------
/library/src/main/java/com/danielstone/materialaboutlibrary/MaterialAboutActivity.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrary;
2 |
3 |
4 | import android.content.Context;
5 | import android.os.AsyncTask;
6 | import android.os.Bundle;
7 | import androidx.annotation.NonNull;
8 | import androidx.annotation.Nullable;
9 | import com.google.android.material.appbar.AppBarLayout;
10 | import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
11 | import androidx.appcompat.app.ActionBar;
12 | import androidx.appcompat.app.AppCompatActivity;
13 | import androidx.recyclerview.widget.LinearLayoutManager;
14 | import androidx.recyclerview.widget.RecyclerView;
15 | import androidx.recyclerview.widget.SimpleItemAnimator;
16 | import androidx.appcompat.widget.Toolbar;
17 | import android.util.TypedValue;
18 | import android.view.MenuItem;
19 |
20 | import com.danielstone.materialaboutlibrary.adapters.MaterialAboutListAdapter;
21 | import com.danielstone.materialaboutlibrary.model.MaterialAboutList;
22 | import com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager;
23 | import com.danielstone.materialaboutlibrary.util.ViewTypeManager;
24 |
25 | import java.lang.ref.WeakReference;
26 |
27 | public abstract class MaterialAboutActivity extends AppCompatActivity {
28 |
29 | private MaterialAboutList list = new MaterialAboutList.Builder().build();
30 | private RecyclerView recyclerView;
31 | private MaterialAboutListAdapter adapter;
32 |
33 | @NonNull
34 | protected abstract MaterialAboutList getMaterialAboutList(@NonNull Context context);
35 |
36 | @Nullable
37 | protected abstract CharSequence getActivityTitle();
38 |
39 | /**
40 | * Get a reference to the recyclerview in case a snackbar needs to be displayed
41 | * @return
42 | */
43 | public RecyclerView getRecyclerView() {
44 | return recyclerView;
45 | }
46 |
47 | @Override
48 | protected void onCreate(@Nullable Bundle savedInstanceState) {
49 | super.onCreate(savedInstanceState);
50 |
51 | setContentView(R.layout.mal_material_about_content);
52 |
53 | CharSequence title = getActivityTitle();
54 | if (title == null)
55 | setTitle(R.string.mal_title_about);
56 | else
57 | setTitle(title);
58 |
59 |
60 | assignViews();
61 | initViews();
62 |
63 | ListTask task = new ListTask(this);
64 | task.execute();
65 | }
66 |
67 | private void assignViews() {
68 | recyclerView = (RecyclerView) findViewById(R.id.mal_recyclerview);
69 | recyclerView.setAlpha(0f);
70 | recyclerView.setTranslationY(20);
71 | }
72 |
73 | private void initViews() {
74 | ActionBar actionBar = getSupportActionBar();
75 | if (actionBar != null) {
76 | actionBar.setDisplayHomeAsUpEnabled(true);
77 | }
78 | adapter = new MaterialAboutListAdapter(getViewTypeManager());
79 | recyclerView.setLayoutManager(new LinearLayoutManager(this));
80 | recyclerView.setAdapter(adapter);
81 | RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
82 | if (animator instanceof SimpleItemAnimator) {
83 | ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
84 | }
85 | }
86 |
87 | @NonNull
88 | protected ViewTypeManager getViewTypeManager() {
89 | return new DefaultViewTypeManager();
90 | }
91 |
92 | @NonNull
93 | protected MaterialAboutList getList() {
94 | return list;
95 | }
96 |
97 | protected boolean shouldAnimate() {
98 | return true;
99 | }
100 |
101 | protected void refreshMaterialAboutList() {
102 | setMaterialAboutList(list);
103 | }
104 |
105 | @Override
106 | public boolean onOptionsItemSelected(MenuItem item) {
107 | if (item.getItemId() == android.R.id.home) {
108 | onBackPressed();
109 | return true;
110 | }
111 | return super.onOptionsItemSelected(item);
112 | }
113 |
114 | private void onTaskFinished(@Nullable MaterialAboutList materialAboutList) {
115 | if (materialAboutList != null) {
116 | list = materialAboutList;
117 | adapter.setData(list.getCards());
118 |
119 | if (shouldAnimate()) {
120 | recyclerView.animate()
121 | .alpha(1f)
122 | .translationY(0f)
123 | .setDuration(600)
124 | .setInterpolator(new FastOutSlowInInterpolator()).start();
125 | } else {
126 | recyclerView.setAlpha(1f);
127 | recyclerView.setTranslationY(0f);
128 | }
129 | } else {
130 | finish();//?? why we remain here anyway?
131 | }
132 | }
133 |
134 | protected void setMaterialAboutList(MaterialAboutList materialAboutList) {
135 | list = materialAboutList;
136 | adapter.setData(list.getCards());
137 | }
138 |
139 | private static class ListTask extends AsyncTask {
140 |
141 | private WeakReference context;
142 |
143 | ListTask(MaterialAboutActivity context) {
144 | this.context = new WeakReference<>(context);
145 | }
146 |
147 | @Override
148 | protected MaterialAboutList doInBackground(String... params) {
149 | return isCancelled() || context.get() == null ? null : context.get().getMaterialAboutList(context.get());
150 | }
151 |
152 | @Override
153 | protected void onPostExecute(MaterialAboutList materialAboutList) {
154 | super.onPostExecute(materialAboutList);
155 | if (context.get() != null) {
156 | if (!context.get().isFinishing()) {
157 | context.get().onTaskFinished(materialAboutList);
158 | }
159 | }
160 | context = null;
161 | }
162 | }
163 | }
164 |
--------------------------------------------------------------------------------
/library/src/main/java/com/danielstone/materialaboutlibrary/MaterialAboutFragment.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrary;
2 |
3 | import android.content.Context;
4 | import android.os.AsyncTask;
5 | import android.os.Bundle;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import androidx.annotation.NonNull;
11 | import androidx.annotation.Nullable;
12 | import androidx.fragment.app.Fragment;
13 | import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
14 | import androidx.recyclerview.widget.LinearLayoutManager;
15 | import androidx.recyclerview.widget.RecyclerView;
16 | import androidx.recyclerview.widget.SimpleItemAnimator;
17 |
18 | import com.danielstone.materialaboutlibrary.adapters.MaterialAboutListAdapter;
19 | import com.danielstone.materialaboutlibrary.model.MaterialAboutList;
20 | import com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager;
21 | import com.danielstone.materialaboutlibrary.util.ViewTypeManager;
22 |
23 | import java.lang.ref.WeakReference;
24 |
25 | public abstract class MaterialAboutFragment extends Fragment {
26 |
27 | private MaterialAboutList list = new MaterialAboutList.Builder().build();
28 | private RecyclerView recyclerView;
29 | private MaterialAboutListAdapter adapter;
30 |
31 | public static MaterialAboutFragment newInstance(MaterialAboutFragment fragment) {
32 | return fragment;
33 | }
34 |
35 | protected abstract MaterialAboutList getMaterialAboutList(Context activityContext);
36 |
37 |
38 | protected boolean shouldAnimate() {
39 | return true;
40 | }
41 |
42 |
43 | @Nullable
44 | @Override
45 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
46 | View rootView = inflater.inflate(R.layout.mal_material_about_content, container, false);
47 |
48 | recyclerView = (RecyclerView) rootView.findViewById(R.id.mal_recyclerview);
49 | adapter = new MaterialAboutListAdapter(getViewTypeManager());
50 | recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
51 | recyclerView.setAdapter(adapter);
52 |
53 | RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
54 | if (animator instanceof SimpleItemAnimator) {
55 | ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
56 | }
57 |
58 | recyclerView.setAlpha(0f);
59 | recyclerView.setTranslationY(20);
60 |
61 | new ListTask(this).execute();
62 |
63 | return rootView;
64 | }
65 |
66 | @NonNull
67 | protected ViewTypeManager getViewTypeManager() {
68 | return new DefaultViewTypeManager();
69 | }
70 |
71 | protected MaterialAboutList getList() {
72 | return list;
73 | }
74 |
75 | protected void setMaterialAboutList(MaterialAboutList materialAboutList) {
76 | list = materialAboutList;
77 | adapter.setData(list.getCards());
78 | }
79 |
80 | private void displayList(){
81 | if (shouldAnimate()) {
82 | recyclerView.animate()
83 | .alpha(1f)
84 | .translationY(0f)
85 | .setDuration(600)
86 | .setInterpolator(new FastOutSlowInInterpolator())
87 | .start();
88 | } else {
89 | recyclerView.setAlpha(1f);
90 | recyclerView.setTranslationY(0f);
91 | }
92 | }
93 |
94 | @Override
95 | public void onPause() {
96 | super.onPause();
97 | }
98 |
99 | protected void refreshMaterialAboutList() {
100 | setMaterialAboutList(list);
101 | }
102 |
103 | private static class ListTask extends AsyncTask {
104 |
105 | private final WeakReference fragmentContextReference;
106 |
107 | ListTask(MaterialAboutFragment materialAboutFragment) {
108 | this.fragmentContextReference = new WeakReference<>(materialAboutFragment);
109 | }
110 |
111 | @Override
112 | protected MaterialAboutList doInBackground(String... params) {
113 | MaterialAboutFragment fragment = fragmentContextReference.get();
114 | return isCancelled() || fragment == null ? null : fragment.getMaterialAboutList(fragment.getActivity());
115 | }
116 |
117 | @Override
118 | protected void onPostExecute(MaterialAboutList materialAboutList) {
119 | MaterialAboutFragment fragment = fragmentContextReference.get();
120 | if (fragment != null) {
121 | fragment.setMaterialAboutList(materialAboutList);
122 | fragment.displayList();
123 | }
124 | fragmentContextReference.clear();
125 | }
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/library/src/main/java/com/danielstone/materialaboutlibrary/adapters/MaterialAboutItemAdapter.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrary.adapters;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.annotation.NonNull;
6 | import androidx.recyclerview.widget.AsyncListDiffer;
7 | import androidx.recyclerview.widget.DiffUtil;
8 | import androidx.recyclerview.widget.RecyclerView;
9 |
10 | import android.util.Log;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 |
15 | import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder;
16 | import com.danielstone.materialaboutlibrary.items.MaterialAboutItem;
17 | import com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager;
18 | import com.danielstone.materialaboutlibrary.util.ViewTypeManager;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 | import java.util.UUID;
23 |
24 |
25 | public class MaterialAboutItemAdapter extends RecyclerView.Adapter {
26 |
27 | private final AsyncListDiffer differ = new AsyncListDiffer(this, DIFF_CALLBACK);
28 |
29 | private ViewTypeManager viewTypeManager;
30 |
31 | private Context context;
32 |
33 | MaterialAboutItemAdapter() {
34 | setHasStableIds(true);
35 | this.viewTypeManager = new DefaultViewTypeManager();
36 | }
37 |
38 | MaterialAboutItemAdapter(ViewTypeManager customViewTypeManager) {
39 | setHasStableIds(true);
40 | this.viewTypeManager = customViewTypeManager;
41 | }
42 |
43 | @NonNull
44 | @Override
45 | public MaterialAboutItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
46 | context = viewGroup.getContext();
47 | if (!(viewGroup instanceof RecyclerView)) {
48 | throw new RuntimeException("Not bound to RecyclerView");
49 | }
50 |
51 | int layoutId = viewTypeManager.getLayout(viewType);
52 |
53 | View view = LayoutInflater.from(viewGroup.getContext()).inflate(layoutId, viewGroup, false);
54 | view.setFocusable(true);
55 |
56 | return viewTypeManager.getViewHolder(viewType, view);
57 | }
58 |
59 | @Override
60 | public void onBindViewHolder(MaterialAboutItemViewHolder holder, int position) {
61 | viewTypeManager.setupItem(getItemViewType(position), holder, differ.getCurrentList().get(position), context);
62 | }
63 |
64 |
65 | @Override
66 | public long getItemId(int position) {
67 | return UUID.fromString(differ.getCurrentList().get(position).getId()).getMostSignificantBits() & Long.MAX_VALUE;
68 | }
69 |
70 | @Override
71 | public int getItemCount() {
72 | return differ.getCurrentList().size();
73 | }
74 |
75 | @Override
76 | public int getItemViewType(int position) {
77 | return differ.getCurrentList().get(position).getType();
78 | }
79 |
80 | public void setData(ArrayList newData) {
81 | List data = new ArrayList<>();
82 | for (MaterialAboutItem item : newData) {
83 | data.add(item.clone());
84 | }
85 | differ.submitList(data);
86 | }
87 |
88 | public List getData() {
89 | return differ.getCurrentList();
90 | }
91 |
92 |
93 | public static final DiffUtil.ItemCallback DIFF_CALLBACK = new DiffUtil.ItemCallback() {
94 | @Override
95 | public boolean areItemsTheSame(MaterialAboutItem oldItem, MaterialAboutItem newItem) {
96 | return oldItem.getId().equals(newItem.getId());
97 | }
98 |
99 | @Override
100 | public boolean areContentsTheSame(MaterialAboutItem oldItem, MaterialAboutItem newItem) {
101 | return oldItem.getDetailString().equals(newItem.getDetailString());
102 | }
103 | };
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/library/src/main/java/com/danielstone/materialaboutlibrary/adapters/MaterialAboutListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrary.adapters;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.core.content.ContextCompat;
6 | import androidx.core.content.res.ResourcesCompat;
7 | import androidx.recyclerview.widget.AsyncListDiffer;
8 | import androidx.recyclerview.widget.DiffUtil;
9 | import androidx.cardview.widget.CardView;
10 | import androidx.recyclerview.widget.LinearLayoutManager;
11 | import androidx.recyclerview.widget.RecyclerView;
12 |
13 | import android.view.LayoutInflater;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 | import android.widget.TextView;
17 |
18 | import com.danielstone.materialaboutlibrary.R;
19 | import com.danielstone.materialaboutlibrary.model.MaterialAboutCard;
20 | import com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager;
21 | import com.danielstone.materialaboutlibrary.util.ViewTypeManager;
22 | import com.google.android.material.card.MaterialCardView;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 | import java.util.UUID;
27 |
28 |
29 | public class MaterialAboutListAdapter extends RecyclerView.Adapter {
30 |
31 |
32 | private final AsyncListDiffer differ = new AsyncListDiffer(this, DIFF_CALLBACK);
33 |
34 | private Context context;
35 |
36 | private ViewTypeManager viewTypeManager;
37 |
38 | private RecyclerView.RecycledViewPool viewPool;
39 |
40 | public MaterialAboutListAdapter() {
41 | setHasStableIds(true);
42 | this.viewTypeManager = new DefaultViewTypeManager();
43 | viewPool = new RecyclerView.RecycledViewPool();
44 | }
45 |
46 | public MaterialAboutListAdapter(ViewTypeManager customViewTypeManager) {
47 | setHasStableIds(true);
48 | this.viewTypeManager = customViewTypeManager;
49 | viewPool = new RecyclerView.RecycledViewPool();
50 | }
51 |
52 | @Override
53 | public MaterialAboutListViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
54 | context = viewGroup.getContext();
55 | if (viewGroup instanceof RecyclerView) {
56 | View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.mal_material_about_list_card, viewGroup, false);
57 | view.setFocusable(true);
58 | return new MaterialAboutListViewHolder(view, viewPool);
59 | } else {
60 | throw new RuntimeException("Not bound to RecyclerView");
61 | }
62 | }
63 |
64 | @Override
65 | public void onBindViewHolder(MaterialAboutListViewHolder holder, int position) {
66 | MaterialAboutCard card = differ.getCurrentList().get(position);
67 |
68 | if (holder.cardView instanceof CardView) {
69 | CardView cardView = (CardView) holder.cardView;
70 | int cardColor = card.getCardColor();
71 | if (cardColor != 0) {
72 | cardView.setCardBackgroundColor(cardColor);
73 | } else {
74 | cardView.setCardBackgroundColor(cardView.getCardBackgroundColor().getDefaultColor());
75 | }
76 | }
77 |
78 | CharSequence title = card.getTitle();
79 | int titleRes = card.getTitleRes();
80 |
81 | holder.title.setVisibility(View.VISIBLE);
82 | if (title != null) {
83 | holder.title.setText(title);
84 | } else if (titleRes != 0) {
85 | holder.title.setText(titleRes);
86 | } else {
87 | holder.title.setVisibility(View.GONE);
88 | }
89 |
90 | int titleColor = card.getTitleColor();
91 |
92 | if (holder.title.getVisibility() == View.VISIBLE) {
93 | if (titleColor != 0) {
94 | holder.title.setTextColor(titleColor);
95 | } else {
96 | holder.title.setTextColor(holder.title.getTextColors().getDefaultColor());
97 | }
98 | }
99 |
100 |
101 | if (holder.cardView instanceof MaterialCardView) {
102 | MaterialCardView materialCardView = (MaterialCardView) holder.cardView;
103 | if (card.isOutline()) {
104 | materialCardView.setStrokeWidth((int) context.getResources().getDimension(R.dimen.mal_stroke_width));
105 | materialCardView.setCardElevation(0);
106 | } else {
107 | materialCardView.setStrokeWidth(0);
108 | materialCardView.setCardElevation(context.getResources().getDimension(R.dimen.mal_card_elevation));
109 | }
110 | }
111 |
112 |
113 | if (card.getCustomAdapter() != null) {
114 | holder.useCustomAdapter(card.getCustomAdapter());
115 | } else {
116 | holder.useMaterialAboutItemAdapter();
117 | ((MaterialAboutItemAdapter) holder.adapter).setData(card.getItems());
118 | }
119 | }
120 |
121 | @Override
122 | public long getItemId(int position) {
123 | return UUID.fromString(differ.getCurrentList().get(position).getId()).getMostSignificantBits() & Long.MAX_VALUE;
124 | }
125 |
126 | @Override
127 | public int getItemCount() {
128 | return differ.getCurrentList().size();
129 | }
130 |
131 | public void setData(ArrayList newData) {
132 | List data = new ArrayList<>();
133 | for (MaterialAboutCard card : newData) {
134 | data.add(card.clone());
135 | }
136 | differ.submitList(data);
137 | }
138 |
139 |
140 | List getData() {
141 | return differ.getCurrentList();
142 | }
143 |
144 | class MaterialAboutListViewHolder extends RecyclerView.ViewHolder {
145 |
146 | final View cardView;
147 | final TextView title;
148 | final RecyclerView recyclerView;
149 | final RecyclerView.RecycledViewPool viewPool;
150 | RecyclerView.Adapter adapter;
151 |
152 | MaterialAboutListViewHolder(View view, RecyclerView.RecycledViewPool viewPool) {
153 | super(view);
154 | this.viewPool = viewPool;
155 | cardView = view.findViewById(R.id.mal_list_card);
156 | title = (TextView) view.findViewById(R.id.mal_list_card_title);
157 | recyclerView = (RecyclerView) view.findViewById(R.id.mal_card_recyclerview);
158 | recyclerView.setLayoutManager(new LinearLayoutManager(context));
159 | recyclerView.setNestedScrollingEnabled(false);
160 | }
161 |
162 | public void useMaterialAboutItemAdapter() {
163 | if (!(adapter instanceof MaterialAboutItemAdapter)) {
164 | adapter = new MaterialAboutItemAdapter(viewTypeManager);
165 | recyclerView.setLayoutManager(new LinearLayoutManager(context));
166 | recyclerView.setRecycledViewPool(viewPool);
167 | recyclerView.setAdapter(adapter);
168 | }
169 | }
170 |
171 | public void useCustomAdapter(RecyclerView.Adapter newAdapter) {
172 | if (adapter == null || !(adapter.getClass().isInstance(newAdapter))) {
173 | recyclerView.setLayoutManager(new LinearLayoutManager(context));
174 | recyclerView.setRecycledViewPool(null);
175 | recyclerView.setAdapter(newAdapter);
176 | }
177 | }
178 | }
179 |
180 |
181 | public static final DiffUtil.ItemCallback DIFF_CALLBACK = new DiffUtil.ItemCallback() {
182 | @Override
183 | public boolean areItemsTheSame(MaterialAboutCard oldItem, MaterialAboutCard newItem) {
184 | return oldItem.getId().equals(newItem.getId());
185 | }
186 |
187 | @Override
188 | public boolean areContentsTheSame(MaterialAboutCard oldItem, MaterialAboutCard newItem) {
189 | boolean result;
190 | result = oldItem.toString().equals(newItem.toString());
191 | if (oldItem.getItems().size() != newItem.getItems().size()) return false;
192 | for (int i = 0; i < oldItem.getItems().size(); i++) {
193 | if (!oldItem.getItems().get(i).getDetailString().equals(newItem.getItems().get(i).getDetailString())) return false;
194 | }
195 | return result;
196 | }
197 | };
198 | }
199 |
--------------------------------------------------------------------------------
/library/src/main/java/com/danielstone/materialaboutlibrary/holders/MaterialAboutItemViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrary.holders;
2 |
3 | import androidx.recyclerview.widget.RecyclerView;
4 | import android.view.View;
5 |
6 | public abstract class MaterialAboutItemViewHolder extends RecyclerView.ViewHolder {
7 |
8 | public MaterialAboutItemViewHolder(View itemView) {
9 | super(itemView);
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutActionItem.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrary.items;
2 |
3 | import android.content.Context;
4 | import android.graphics.drawable.Drawable;
5 | import android.os.Build;
6 | import androidx.annotation.DrawableRes;
7 | import androidx.annotation.IntDef;
8 | import androidx.annotation.StringRes;
9 | import android.text.Html;
10 | import android.util.TypedValue;
11 | import android.view.Gravity;
12 | import android.view.View;
13 | import android.widget.ImageView;
14 | import android.widget.LinearLayout;
15 | import android.widget.TextView;
16 |
17 | import com.danielstone.materialaboutlibrary.R;
18 | import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder;
19 | import com.danielstone.materialaboutlibrary.util.ViewTypeManager;
20 |
21 | import java.lang.annotation.Retention;
22 | import java.lang.annotation.RetentionPolicy;
23 |
24 | import static android.view.View.GONE;
25 |
26 | public class MaterialAboutActionItem extends MaterialAboutItem {
27 |
28 | public static final int GRAVITY_TOP = 0;
29 | public static final int GRAVITY_MIDDLE = 1;
30 | public static final int GRAVITY_BOTTOM = 2;
31 | private CharSequence text = null;
32 | private int textRes = 0;
33 | private CharSequence subText = null;
34 | private int subTextRes = 0;
35 | private Drawable icon = null;
36 | private int iconRes = 0;
37 | private boolean showIcon = true;
38 | private int iconGravity = GRAVITY_MIDDLE;
39 | private MaterialAboutItemOnClickAction onClickAction = null;
40 | private MaterialAboutItemOnClickAction onLongClickAction = null;
41 |
42 | private MaterialAboutActionItem(Builder builder) {
43 | super();
44 | this.text = builder.text;
45 | this.textRes = builder.textRes;
46 |
47 | this.subText = builder.subText;
48 | this.subTextRes = builder.subTextRes;
49 |
50 | this.icon = builder.icon;
51 | this.iconRes = builder.iconRes;
52 |
53 | this.showIcon = builder.showIcon;
54 |
55 | this.iconGravity = builder.iconGravity;
56 |
57 | this.onClickAction = builder.onClickAction;
58 | this.onLongClickAction = builder.onLongClickAction;
59 | }
60 |
61 | public MaterialAboutActionItem(CharSequence text, CharSequence subText, Drawable icon, MaterialAboutItemOnClickAction onClickAction) {
62 | this.text = text;
63 | this.subText = subText;
64 | this.icon = icon;
65 | this.onClickAction = onClickAction;
66 | }
67 |
68 | public MaterialAboutActionItem(CharSequence text, CharSequence subText, Drawable icon) {
69 | this.text = text;
70 | this.subText = subText;
71 | this.icon = icon;
72 | }
73 |
74 | public MaterialAboutActionItem(int textRes, int subTextRes, int iconRes, MaterialAboutItemOnClickAction onClickAction) {
75 | this.textRes = textRes;
76 | this.subTextRes = subTextRes;
77 | this.iconRes = iconRes;
78 | this.onClickAction = onClickAction;
79 | }
80 |
81 | public MaterialAboutActionItem(int textRes, int subTextRes, int iconRes) {
82 | this.textRes = textRes;
83 | this.subTextRes = subTextRes;
84 | this.iconRes = iconRes;
85 | }
86 |
87 | public static MaterialAboutItemViewHolder getViewHolder(View view) {
88 | return new MaterialAboutActionItemViewHolder(view);
89 | }
90 |
91 | public static void setupItem(MaterialAboutActionItemViewHolder holder, MaterialAboutActionItem item, Context context) {
92 | CharSequence text = item.getText();
93 | int textRes = item.getTextRes();
94 |
95 | holder.text.setVisibility(View.VISIBLE);
96 | if (text != null) {
97 | holder.text.setText(text);
98 | } else if (textRes != 0) {
99 | holder.text.setText(textRes);
100 | } else {
101 | holder.text.setVisibility(GONE);
102 | }
103 |
104 | CharSequence subText = item.getSubText();
105 | int subTextRes = item.getSubTextRes();
106 |
107 | holder.subText.setVisibility(View.VISIBLE);
108 | if (subText != null) {
109 | holder.subText.setText(subText);
110 | } else if (subTextRes != 0) {
111 | holder.subText.setText(subTextRes);
112 | } else {
113 | holder.subText.setVisibility(GONE);
114 | }
115 |
116 | if (item.shouldShowIcon()) {
117 | holder.icon.setVisibility(View.VISIBLE);
118 | Drawable drawable = item.getIcon();
119 | int drawableRes = item.getIconRes();
120 | if (drawable != null) {
121 | holder.icon.setImageDrawable(drawable);
122 | } else if (drawableRes != 0) {
123 | holder.icon.setImageResource(drawableRes);
124 | }
125 | } else {
126 | holder.icon.setVisibility(GONE);
127 | }
128 |
129 | LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) holder.icon.getLayoutParams();
130 | switch (item.getIconGravity()) {
131 | case MaterialAboutActionItem.GRAVITY_TOP:
132 | params.gravity = Gravity.TOP;
133 | break;
134 | case MaterialAboutActionItem.GRAVITY_MIDDLE:
135 | params.gravity = Gravity.CENTER_VERTICAL;
136 | break;
137 | case MaterialAboutActionItem.GRAVITY_BOTTOM:
138 | params.gravity = Gravity.BOTTOM;
139 | break;
140 | }
141 | holder.icon.setLayoutParams(params);
142 |
143 | int pL = 0, pT = 0, pR = 0, pB = 0;
144 | if (Build.VERSION.SDK_INT < 21) {
145 | pL = holder.view.getPaddingLeft();
146 | pT = holder.view.getPaddingTop();
147 | pR = holder.view.getPaddingRight();
148 | pB = holder.view.getPaddingBottom();
149 | }
150 |
151 | if (item.getOnClickAction() != null || item.getOnLongClickAction() != null) {
152 | TypedValue outValue = new TypedValue();
153 | context.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true);
154 | holder.view.setBackgroundResource(outValue.resourceId);
155 | } else {
156 | holder.view.setBackgroundResource(0);
157 | }
158 | holder.setOnClickAction(item.getOnClickAction());
159 | holder.setOnLongClickAction(item.getOnLongClickAction());
160 |
161 | if (Build.VERSION.SDK_INT < 21) {
162 | holder.view.setPadding(pL, pT, pR, pB);
163 | }
164 | }
165 |
166 | @Override
167 | public int getType() {
168 | return ViewTypeManager.ItemType.ACTION_ITEM;
169 | }
170 |
171 | @Override
172 | public String getDetailString() {
173 | return "MaterialAboutActionItem{" +
174 | "text=" + text +
175 | ", textRes=" + textRes +
176 | ", subText=" + subText +
177 | ", subTextRes=" + subTextRes +
178 | ", icon=" + icon +
179 | ", iconRes=" + iconRes +
180 | ", showIcon=" + showIcon +
181 | ", iconGravity=" + iconGravity +
182 | ", onClickAction=" + onClickAction +
183 | ", onLongClickAction=" + onLongClickAction +
184 | '}';
185 | }
186 |
187 | public MaterialAboutActionItem(MaterialAboutActionItem item) {
188 | this.id = item.getId();
189 | this.text = item.getText();
190 | this.textRes = item.getTextRes();
191 | this.subText = item.getSubText();
192 | this.subTextRes = item.getSubTextRes();
193 | this.icon = item.getIcon();
194 | this.iconRes = item.getIconRes();
195 | this.showIcon = item.showIcon;
196 | this.iconGravity = item.iconGravity;
197 | this.onClickAction = item.onClickAction;
198 | this.onLongClickAction = item.onLongClickAction;
199 | }
200 |
201 | @Override
202 | public MaterialAboutItem clone() {
203 | return new MaterialAboutActionItem(this);
204 | }
205 |
206 | public CharSequence getText() {
207 | return text;
208 | }
209 | public MaterialAboutActionItem setText(CharSequence text) {
210 | this.textRes = 0;
211 | this.text = text;
212 | return this;
213 | }
214 |
215 | public int getTextRes() {
216 | return textRes;
217 | }
218 |
219 | public MaterialAboutActionItem setTextRes(int textRes) {
220 | this.text = null;
221 | this.textRes = textRes;
222 | return this;
223 | }
224 |
225 | public CharSequence getSubText() {
226 | return subText;
227 | }
228 |
229 | public MaterialAboutActionItem setSubText(CharSequence subText) {
230 | this.subTextRes = 0;
231 | this.subText = subText;
232 | return this;
233 | }
234 |
235 | public int getSubTextRes() {
236 | return subTextRes;
237 | }
238 |
239 | public MaterialAboutActionItem setSubTextRes(int subTextRes) {
240 | this.subText = null;
241 | this.subTextRes = subTextRes;
242 | return this;
243 | }
244 |
245 | public Drawable getIcon() {
246 | return icon;
247 | }
248 |
249 | public MaterialAboutActionItem setIcon(Drawable icon) {
250 | this.iconRes = 0;
251 | this.icon = icon;
252 | return this;
253 | }
254 |
255 | public int getIconRes() {
256 | return iconRes;
257 | }
258 |
259 | public MaterialAboutActionItem setIconRes(int iconRes) {
260 | this.icon = null;
261 | this.iconRes = iconRes;
262 | return this;
263 | }
264 |
265 | public boolean shouldShowIcon() {
266 | return showIcon;
267 | }
268 |
269 | public MaterialAboutActionItem setShouldShowIcon(boolean showIcon) {
270 | this.showIcon = showIcon;
271 | return this;
272 | }
273 |
274 | @IconGravity
275 | public int getIconGravity() {
276 | return iconGravity;
277 | }
278 |
279 | public MaterialAboutActionItem setIconGravity(int iconGravity) {
280 | this.iconGravity = iconGravity;
281 | return this;
282 | }
283 |
284 | public MaterialAboutItemOnClickAction getOnClickAction() {
285 | return onClickAction;
286 | }
287 |
288 | public MaterialAboutActionItem setOnClickAction(MaterialAboutItemOnClickAction onClickAction) {
289 | this.onClickAction = onClickAction;
290 | return this;
291 | }
292 |
293 | public MaterialAboutItemOnClickAction getOnLongClickAction() {
294 | return onLongClickAction;
295 | }
296 |
297 | public MaterialAboutActionItem setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) {
298 | this.onLongClickAction = onLongClickAction;
299 | return this;
300 | }
301 |
302 | @Retention(RetentionPolicy.SOURCE)
303 | @IntDef({GRAVITY_TOP, GRAVITY_MIDDLE, GRAVITY_BOTTOM})
304 | public @interface IconGravity {
305 | }
306 |
307 | public static class MaterialAboutActionItemViewHolder extends MaterialAboutItemViewHolder implements View.OnClickListener, View.OnLongClickListener {
308 | public final View view;
309 | public final ImageView icon;
310 | public final TextView text;
311 | public final TextView subText;
312 | private MaterialAboutItemOnClickAction onClickAction;
313 | private MaterialAboutItemOnClickAction onLongClickAction;
314 |
315 | MaterialAboutActionItemViewHolder(View view) {
316 | super(view);
317 | this.view = view;
318 | icon = (ImageView) view.findViewById(R.id.mal_item_image);
319 | text = (TextView) view.findViewById(R.id.mal_item_text);
320 | subText = (TextView) view.findViewById(R.id.mal_action_item_subtext);
321 | }
322 |
323 | public void setOnClickAction(MaterialAboutItemOnClickAction onClickAction) {
324 | this.onClickAction = onClickAction;
325 | view.setOnClickListener(onClickAction != null ? this : null);
326 | }
327 |
328 | public void setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) {
329 | this.onLongClickAction = onLongClickAction;
330 | view.setOnLongClickListener(onLongClickAction != null ? this : null);
331 | }
332 |
333 | @Override
334 | public void onClick(View v) {
335 | if (onClickAction != null) {
336 | onClickAction.onClick();
337 | }
338 | }
339 |
340 | @Override
341 | public boolean onLongClick(View v) {
342 | if (onLongClickAction != null) {
343 | onLongClickAction.onClick();
344 | return true;
345 | }
346 | return false;
347 | }
348 | }
349 |
350 | public static class Builder {
351 |
352 | MaterialAboutItemOnClickAction onClickAction = null;
353 | MaterialAboutItemOnClickAction onLongClickAction = null;
354 | private CharSequence text = null;
355 | @StringRes
356 | private int textRes = 0;
357 | private CharSequence subText = null;
358 | @StringRes
359 | private int subTextRes = 0;
360 | private Drawable icon = null;
361 | @DrawableRes
362 | private int iconRes = 0;
363 | private boolean showIcon = true;
364 | @IconGravity
365 | private int iconGravity = GRAVITY_MIDDLE;
366 |
367 | public Builder text(CharSequence text) {
368 | this.text = text;
369 | this.textRes = 0;
370 | return this;
371 | }
372 |
373 | public Builder text(@StringRes int text) {
374 | this.textRes = text;
375 | this.text = null;
376 | return this;
377 | }
378 |
379 | public Builder subText(CharSequence subText) {
380 | this.subText = subText;
381 | this.subTextRes = 0;
382 | return this;
383 | }
384 |
385 | public Builder subText(@StringRes int subTextRes) {
386 | this.subText = null;
387 | this.subTextRes = subTextRes;
388 | return this;
389 | }
390 |
391 | public Builder subTextHtml(String subTextHtml) {
392 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
393 | this.subText = Html.fromHtml(subTextHtml, Html.FROM_HTML_MODE_LEGACY);
394 | } else {
395 | //noinspection deprecation
396 | this.subText = Html.fromHtml(subTextHtml);
397 | }
398 | this.subTextRes = 0;
399 | return this;
400 | }
401 |
402 | public Builder icon(Drawable icon) {
403 | this.icon = icon;
404 | this.iconRes = 0;
405 | return this;
406 | }
407 |
408 | public Builder icon(@DrawableRes int iconRes) {
409 | this.icon = null;
410 | this.iconRes = iconRes;
411 | return this;
412 | }
413 |
414 | public Builder showIcon(boolean showIcon) {
415 | this.showIcon = showIcon;
416 | return this;
417 | }
418 |
419 | public Builder setIconGravity(@IconGravity int iconGravity) {
420 | this.iconGravity = iconGravity;
421 | return this;
422 | }
423 |
424 | public Builder setOnClickAction(MaterialAboutItemOnClickAction onClickAction) {
425 | this.onClickAction = onClickAction;
426 | return this;
427 | }
428 |
429 | public Builder setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) {
430 | this.onLongClickAction = onLongClickAction;
431 | return this;
432 | }
433 |
434 | public MaterialAboutActionItem build() {
435 | return new MaterialAboutActionItem(this);
436 | }
437 | }
438 | }
439 |
--------------------------------------------------------------------------------
/library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItem.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrary.items;
2 |
3 | import java.util.UUID;
4 |
5 | public abstract class MaterialAboutItem {
6 |
7 | public String id = "NO-UUID";
8 |
9 | public MaterialAboutItem() {
10 | this.id = UUID.randomUUID().toString();
11 | }
12 |
13 | public String getId() {
14 | return id;
15 | }
16 |
17 | public abstract int getType();
18 |
19 | public abstract String getDetailString();
20 |
21 | public abstract MaterialAboutItem clone();
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutItemOnClickAction.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrary.items;
2 |
3 | public interface MaterialAboutItemOnClickAction {
4 | void onClick();
5 | }
6 |
--------------------------------------------------------------------------------
/library/src/main/java/com/danielstone/materialaboutlibrary/items/MaterialAboutTitleItem.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrary.items;
2 |
3 |
4 | import android.content.Context;
5 | import android.graphics.drawable.Drawable;
6 | import android.os.Build;
7 | import androidx.annotation.DrawableRes;
8 | import androidx.annotation.StringRes;
9 | import android.util.TypedValue;
10 | import android.view.View;
11 | import android.widget.ImageView;
12 | import android.widget.TextView;
13 |
14 | import com.danielstone.materialaboutlibrary.R;
15 | import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder;
16 | import com.danielstone.materialaboutlibrary.util.ViewTypeManager;
17 |
18 | import static android.view.View.GONE;
19 |
20 | public class MaterialAboutTitleItem extends MaterialAboutItem {
21 |
22 | private CharSequence text = null;
23 | private int textRes = 0;
24 | private CharSequence desc = null;
25 | private int descRes = 0;
26 | private Drawable icon = null;
27 | private int iconRes = 0;
28 | private MaterialAboutItemOnClickAction onClickAction = null;
29 | private MaterialAboutItemOnClickAction onLongClickAction = null;
30 |
31 | private MaterialAboutTitleItem(MaterialAboutTitleItem.Builder builder) {
32 | super();
33 | this.text = builder.text;
34 | this.textRes = builder.textRes;
35 |
36 | this.desc = builder.desc;
37 | this.descRes = builder.descRes;
38 |
39 | this.icon = builder.icon;
40 | this.iconRes = builder.iconRes;
41 |
42 | this.onClickAction = builder.onClickAction;
43 | this.onLongClickAction = builder.onLongClickAction;
44 | }
45 |
46 | public MaterialAboutTitleItem(CharSequence text, CharSequence desc, Drawable icon) {
47 | this.text = text;
48 | this.desc = desc;
49 | this.icon = icon;
50 | }
51 |
52 | public MaterialAboutTitleItem(int textRes, int descRes, int iconRes) {
53 | this.textRes = textRes;
54 | this.descRes = descRes;
55 | this.iconRes = iconRes;
56 | }
57 |
58 | public static MaterialAboutItemViewHolder getViewHolder(View view) {
59 | return new MaterialAboutTitleItem.MaterialAboutTitleItemViewHolder(view);
60 | }
61 |
62 | public static void setupItem(MaterialAboutTitleItemViewHolder holder, MaterialAboutTitleItem item, Context context) {
63 |
64 | CharSequence text = item.getText();
65 | int textRes = item.getTextRes();
66 |
67 | holder.text.setVisibility(View.VISIBLE);
68 | if (text != null) {
69 | holder.text.setText(text);
70 | } else if (textRes != 0) {
71 | holder.text.setText(textRes);
72 | } else {
73 | holder.text.setVisibility(GONE);
74 | }
75 |
76 | CharSequence desc = item.getDesc();
77 | int descRes = item.getDescRes();
78 |
79 | holder.desc.setVisibility(View.VISIBLE);
80 | if (desc != null) {
81 | holder.desc.setText(desc);
82 | } else if (descRes != 0) {
83 | holder.desc.setText(descRes);
84 | } else {
85 | holder.desc.setVisibility(GONE);
86 | }
87 |
88 | Drawable drawable = item.getIcon();
89 | int drawableRes = item.getIconRes();
90 | if (drawable != null) {
91 | holder.icon.setImageDrawable(drawable);
92 | } else if (drawableRes != 0) {
93 | holder.icon.setImageResource(drawableRes);
94 | }
95 |
96 | int pL = 0, pT = 0, pR = 0, pB = 0;
97 | if (Build.VERSION.SDK_INT < 21) {
98 | pL = holder.view.getPaddingLeft();
99 | pT = holder.view.getPaddingTop();
100 | pR = holder.view.getPaddingRight();
101 | pB = holder.view.getPaddingBottom();
102 | }
103 |
104 | if (item.getOnClickAction() != null || item.getOnLongClickAction() != null) {
105 | TypedValue outValue = new TypedValue();
106 | context.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true);
107 | holder.view.setBackgroundResource(outValue.resourceId);
108 | } else {
109 | holder.view.setBackgroundResource(0);
110 | }
111 | holder.setOnClickAction(item.getOnClickAction());
112 | holder.setOnLongClickAction(item.getOnLongClickAction());
113 |
114 | if (Build.VERSION.SDK_INT < 21) {
115 | holder.view.setPadding(pL, pT, pR, pB);
116 | }
117 | }
118 |
119 | @Override
120 | public int getType() {
121 | return ViewTypeManager.ItemType.TITLE_ITEM;
122 | }
123 |
124 | @Override
125 | public String getDetailString() {
126 | return "MaterialAboutTitleItem{" +
127 | "text=" + text +
128 | ", textRes=" + textRes +
129 | ", desc=" + desc +
130 | ", descRes=" + descRes +
131 | ", icon=" + icon +
132 | ", iconRes=" + iconRes +
133 | ", onClickAction=" + onClickAction +
134 | ", onLongClickAction=" + onLongClickAction +
135 | '}';
136 | }
137 |
138 | public MaterialAboutTitleItem(MaterialAboutTitleItem item) {
139 | this.id = item.getId();
140 | this.text = item.getText();
141 | this.textRes = item.getTextRes();
142 | this.desc = item.getDesc();
143 | this.descRes = item.getDescRes();
144 | this.icon = item.getIcon();
145 | this.iconRes = item.getIconRes();
146 | this.onClickAction = item.getOnClickAction();
147 | this.onLongClickAction = item.getOnLongClickAction();
148 | }
149 |
150 | @Override
151 | public MaterialAboutTitleItem clone() {
152 | return new MaterialAboutTitleItem(this);
153 | }
154 |
155 | public CharSequence getText() {
156 | return text;
157 | }
158 |
159 | public MaterialAboutTitleItem setText(CharSequence text) {
160 | this.textRes = 0;
161 | this.text = text;
162 | return this;
163 | }
164 |
165 | public int getTextRes() {
166 | return textRes;
167 | }
168 |
169 | public MaterialAboutTitleItem setTextRes(int textRes) {
170 | this.text = null;
171 | this.textRes = textRes;
172 | return this;
173 | }
174 |
175 | public CharSequence getDesc() {
176 | return desc;
177 | }
178 |
179 | public MaterialAboutTitleItem setDesc(CharSequence desc) {
180 | this.descRes = 0;
181 | this.desc = desc;
182 | return this;
183 | }
184 |
185 | public int getDescRes() {
186 | return descRes;
187 | }
188 |
189 | public MaterialAboutTitleItem setDescRes(int descRes) {
190 | this.desc = null;
191 | this.descRes = textRes;
192 | return this;
193 | }
194 |
195 | public Drawable getIcon() {
196 | return icon;
197 | }
198 |
199 | public MaterialAboutTitleItem setIcon(Drawable icon) {
200 | this.iconRes = 0;
201 | this.icon = icon;
202 | return this;
203 | }
204 |
205 | public int getIconRes() {
206 | return iconRes;
207 | }
208 |
209 | public MaterialAboutTitleItem setIconRes(int iconRes) {
210 | this.icon = null;
211 | this.iconRes = iconRes;
212 | return this;
213 | }
214 |
215 | public MaterialAboutItemOnClickAction getOnClickAction() {
216 | return onClickAction;
217 | }
218 |
219 | public MaterialAboutTitleItem setOnClickAction(MaterialAboutItemOnClickAction onClickAction) {
220 | this.onClickAction = onClickAction;
221 | return this;
222 | }
223 |
224 | public MaterialAboutItemOnClickAction getOnLongClickAction() {
225 | return onLongClickAction;
226 | }
227 |
228 | public MaterialAboutTitleItem setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) {
229 | this.onLongClickAction = onLongClickAction;
230 | return this;
231 | }
232 | public static class MaterialAboutTitleItemViewHolder extends MaterialAboutItemViewHolder implements View.OnClickListener, View.OnLongClickListener {
233 | public final View view;
234 | public final ImageView icon;
235 | public final TextView text;
236 | public final TextView desc;
237 | private MaterialAboutItemOnClickAction onClickAction;
238 | private MaterialAboutItemOnClickAction onLongClickAction;
239 |
240 | MaterialAboutTitleItemViewHolder(View view) {
241 | super(view);
242 | this.view = view;
243 | icon = (ImageView) view.findViewById(R.id.mal_item_image);
244 | text = (TextView) view.findViewById(R.id.mal_item_text);
245 | desc = (TextView) view.findViewById(R.id.mal_item_desc);
246 | }
247 |
248 | public void setOnClickAction(MaterialAboutItemOnClickAction onClickAction) {
249 | this.onClickAction = onClickAction;
250 | if (onClickAction != null) {
251 | view.setOnClickListener(this);
252 | } else {
253 | view.setClickable(false);
254 | }
255 | }
256 |
257 | public void setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) {
258 | this.onLongClickAction = onLongClickAction;
259 | if (onLongClickAction != null) {
260 | view.setOnLongClickListener(this);
261 | } else {
262 | view.setLongClickable(false);
263 | }
264 | }
265 |
266 | @Override
267 | public void onClick(View v) {
268 | if (onClickAction != null) {
269 | onClickAction.onClick();
270 | }
271 | }
272 |
273 | @Override
274 | public boolean onLongClick(View v) {
275 | if (onLongClickAction != null) {
276 | onLongClickAction.onClick();
277 | return true;
278 | }
279 | return false;
280 | }
281 | }
282 |
283 | public static class Builder {
284 |
285 | MaterialAboutItemOnClickAction onClickAction = null;
286 | MaterialAboutItemOnClickAction onLongClickAction = null;
287 | private CharSequence text = null;
288 | @StringRes
289 | private int textRes = 0;
290 | private CharSequence desc = null;
291 | @StringRes
292 | private int descRes = 0;
293 | private Drawable icon = null;
294 | @DrawableRes
295 | private int iconRes = 0;
296 |
297 | public MaterialAboutTitleItem.Builder text(CharSequence text) {
298 | this.text = text;
299 | this.textRes = 0;
300 | return this;
301 | }
302 |
303 |
304 | public MaterialAboutTitleItem.Builder text(@StringRes int text) {
305 | this.textRes = text;
306 | this.text = null;
307 | return this;
308 | }
309 |
310 | public MaterialAboutTitleItem.Builder desc(CharSequence desc) {
311 | this.desc = desc;
312 | this.descRes = 0;
313 | return this;
314 | }
315 |
316 |
317 | public MaterialAboutTitleItem.Builder desc(@StringRes int desc) {
318 | this.descRes = desc;
319 | this.desc = null;
320 | return this;
321 | }
322 |
323 | public MaterialAboutTitleItem.Builder icon(Drawable icon) {
324 | this.icon = icon;
325 | this.iconRes = 0;
326 | return this;
327 | }
328 |
329 |
330 | public MaterialAboutTitleItem.Builder icon(@DrawableRes int iconRes) {
331 | this.icon = null;
332 | this.iconRes = iconRes;
333 | return this;
334 | }
335 |
336 | public MaterialAboutTitleItem.Builder setOnClickAction(MaterialAboutItemOnClickAction onClickAction) {
337 | this.onClickAction = onClickAction;
338 | return this;
339 | }
340 |
341 | public MaterialAboutTitleItem.Builder setOnLongClickAction(MaterialAboutItemOnClickAction onLongClickAction) {
342 | this.onLongClickAction = onLongClickAction;
343 | return this;
344 | }
345 |
346 | public MaterialAboutTitleItem build() {
347 | return new MaterialAboutTitleItem(this);
348 | }
349 | }
350 | }
351 |
--------------------------------------------------------------------------------
/library/src/main/java/com/danielstone/materialaboutlibrary/model/MaterialAboutCard.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrary.model;
2 |
3 |
4 | import androidx.annotation.ColorInt;
5 | import androidx.annotation.StringRes;
6 | import androidx.annotation.StyleRes;
7 | import androidx.recyclerview.widget.RecyclerView;
8 |
9 | import com.danielstone.materialaboutlibrary.items.MaterialAboutItem;
10 |
11 | import java.util.ArrayList;
12 | import java.util.Collections;
13 | import java.util.UUID;
14 |
15 | public class MaterialAboutCard {
16 |
17 | private String id = UUID.randomUUID().toString();
18 |
19 | private CharSequence title = null;
20 | private int titleRes = 0;
21 |
22 | private int titleColor = 0;
23 | private int cardColor = 0;
24 | private boolean outline = true;
25 |
26 | private RecyclerView.Adapter customAdapter = null;
27 | private ArrayList items = new ArrayList<>();
28 | ;
29 |
30 | private MaterialAboutCard(Builder builder) {
31 | this.title = builder.title;
32 | this.titleRes = builder.titleRes;
33 | this.titleColor = builder.titleColor;
34 | this.cardColor = builder.cardColor;
35 | this.items = builder.items;
36 | this.customAdapter = builder.customAdapter;
37 | this.outline = builder.outline;
38 | }
39 |
40 | public MaterialAboutCard(CharSequence title, MaterialAboutItem... materialAboutItems) {
41 | this.title = title;
42 | Collections.addAll(items, materialAboutItems);
43 | }
44 |
45 | public MaterialAboutCard(int titleRes, MaterialAboutItem... materialAboutItems) {
46 | this.titleRes = titleRes;
47 | Collections.addAll(items, materialAboutItems);
48 | }
49 |
50 | public CharSequence getTitle() {
51 | return title;
52 | }
53 |
54 | public int getTitleRes() {
55 | return titleRes;
56 | }
57 |
58 | public int getTitleColor() {
59 | return titleColor;
60 | }
61 |
62 | public int getCardColor() {
63 | return cardColor;
64 | }
65 |
66 | public boolean isOutline() {
67 | return outline;
68 | }
69 |
70 | public ArrayList getItems() {
71 | return items;
72 | }
73 |
74 | public static class Builder {
75 | private CharSequence title = null;
76 | @StringRes
77 | private int titleRes = 0;
78 |
79 | @ColorInt
80 | private int titleColor = 0;
81 |
82 | @ColorInt
83 | private int cardColor = 0;
84 |
85 | private boolean outline = true;
86 |
87 | private ArrayList items = new ArrayList<>();
88 | private RecyclerView.Adapter customAdapter = null;
89 |
90 | public Builder title(CharSequence title) {
91 | this.title = title;
92 | this.titleRes = 0;
93 | return this;
94 | }
95 |
96 | public Builder title(@StringRes int titleRes) {
97 | this.titleRes = titleRes;
98 | this.title = null;
99 | return this;
100 | }
101 |
102 | public Builder titleColor(@ColorInt int color) {
103 | this.titleColor = color;
104 | return this;
105 | }
106 |
107 | public Builder cardColor(@ColorInt int cardColor) {
108 | this.cardColor = cardColor;
109 | return this;
110 | }
111 |
112 | /**
113 | * Use outlined card design - true by default
114 | * @param outline false to enable elevation
115 | * @return builder instance
116 | */
117 | public Builder outline(boolean outline) {
118 | this.outline = outline;
119 | return this;
120 | }
121 |
122 | public Builder addItem(MaterialAboutItem item) {
123 | this.items.add(item);
124 | return this;
125 | }
126 |
127 | public Builder customAdapter(RecyclerView.Adapter customAdapter) {
128 | this.customAdapter = customAdapter;
129 | return this;
130 | }
131 |
132 | public MaterialAboutCard build() {
133 | return new MaterialAboutCard(this);
134 | }
135 | }
136 |
137 | public String getId() {
138 | return id;
139 | }
140 |
141 | public RecyclerView.Adapter getCustomAdapter() {
142 | return customAdapter;
143 | }
144 |
145 | @Override
146 | public String toString() {
147 | String result = "MaterialAboutCard{" +
148 | "id='" + id + '\'' +
149 | ", title=" + title +
150 | ", titleRes=" + titleRes +
151 | ", titleColor=" + titleColor +
152 | ", customAdapter=" + customAdapter +
153 | ", outline=" + outline +
154 | ", cardColor=" + cardColor + '}';
155 | return result;
156 | }
157 |
158 | public MaterialAboutCard(MaterialAboutCard card) {
159 | this.id = card.getId();
160 | this.title = card.getTitle();
161 | this.titleRes = card.getTitleRes();
162 | this.titleColor = card.getTitleColor();
163 | this.cardColor = card.getCardColor();
164 | this.items = new ArrayList<>();
165 | this.outline = card.isOutline();
166 | this.customAdapter = card.getCustomAdapter();
167 | for (MaterialAboutItem item : card.items) {
168 | this.items.add(item.clone());
169 | }
170 | }
171 |
172 | public MaterialAboutCard clone() {
173 | return new MaterialAboutCard(this);
174 | }
175 |
176 | }
177 |
--------------------------------------------------------------------------------
/library/src/main/java/com/danielstone/materialaboutlibrary/model/MaterialAboutList.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrary.model;
2 |
3 |
4 | import java.util.ArrayList;
5 | import java.util.Collections;
6 |
7 | public class MaterialAboutList {
8 |
9 | private ArrayList cards = new ArrayList<>();
10 |
11 | private MaterialAboutList(Builder builder) {
12 | this.cards = builder.cards;
13 | }
14 |
15 | public MaterialAboutList(MaterialAboutCard... materialAboutCards) {
16 | Collections.addAll(cards, materialAboutCards);
17 | }
18 |
19 | public MaterialAboutList addCard(MaterialAboutCard card) {
20 | cards.add(card);
21 | return this;
22 | }
23 |
24 | public MaterialAboutList clearCards(MaterialAboutCard card) {
25 | cards.clear();
26 | return this;
27 | }
28 |
29 | public ArrayList getCards() {
30 | return cards;
31 | }
32 |
33 | public static class Builder {
34 | private ArrayList cards = new ArrayList<>();
35 |
36 | public Builder addCard(MaterialAboutCard card) {
37 | this.cards.add(card);
38 | return this;
39 | }
40 |
41 | public MaterialAboutList build() {
42 | return new MaterialAboutList(this);
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/library/src/main/java/com/danielstone/materialaboutlibrary/util/DefaultViewTypeManager.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrary.util;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder;
7 | import com.danielstone.materialaboutlibrary.items.MaterialAboutActionItem;
8 | import com.danielstone.materialaboutlibrary.items.MaterialAboutItem;
9 | import com.danielstone.materialaboutlibrary.items.MaterialAboutTitleItem;
10 |
11 | import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemLayout.ACTION_LAYOUT;
12 | import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemLayout.TITLE_LAYOUT;
13 | import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemType.ACTION_ITEM;
14 | import static com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager.ItemType.TITLE_ITEM;
15 |
16 | public class DefaultViewTypeManager extends ViewTypeManager {
17 |
18 | public static final class ItemType {
19 | public static final int ACTION_ITEM = ViewTypeManager.ItemType.ACTION_ITEM;
20 | public static final int TITLE_ITEM = ViewTypeManager.ItemType.TITLE_ITEM;
21 | }
22 |
23 | public static final class ItemLayout {
24 | public static final int ACTION_LAYOUT = ViewTypeManager.ItemLayout.ACTION_LAYOUT;
25 | public static final int TITLE_LAYOUT = ViewTypeManager.ItemLayout.TITLE_LAYOUT;
26 | }
27 |
28 | public int getLayout(int itemType) {
29 | switch (itemType) {
30 | case ACTION_ITEM:
31 | return ACTION_LAYOUT;
32 | case TITLE_ITEM:
33 | return TITLE_LAYOUT;
34 | default:
35 | return -1;
36 | }
37 | }
38 |
39 | public MaterialAboutItemViewHolder getViewHolder(int itemType, View view) {
40 | switch (itemType) {
41 | case ACTION_ITEM:
42 | return MaterialAboutActionItem.getViewHolder(view);
43 | case TITLE_ITEM:
44 | return MaterialAboutTitleItem.getViewHolder(view);
45 | default:
46 | return null;
47 | }
48 | }
49 |
50 | public void setupItem(int itemType, MaterialAboutItemViewHolder holder, MaterialAboutItem item, Context context) {
51 | switch (itemType) {
52 | case ACTION_ITEM:
53 | MaterialAboutActionItem.setupItem((MaterialAboutActionItem.MaterialAboutActionItemViewHolder) holder, (MaterialAboutActionItem) item, context);
54 | break;
55 | case TITLE_ITEM:
56 | MaterialAboutTitleItem.setupItem((MaterialAboutTitleItem.MaterialAboutTitleItemViewHolder) holder, (MaterialAboutTitleItem) item, context);
57 | break;
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/library/src/main/java/com/danielstone/materialaboutlibrary/util/OpenSourceLicense.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrary.util;
2 |
3 | import com.danielstone.materialaboutlibrary.R;
4 |
5 | public enum OpenSourceLicense {
6 | APACHE_2, MIT, GNU_GPL_3, BSD;
7 |
8 | public int getResourceId() {
9 | switch (this) {
10 | case APACHE_2:
11 | return R.string.license_apache2;
12 | case MIT:
13 | return R.string.license_mit;
14 | case GNU_GPL_3:
15 | return R.string.license_gpl;
16 | case BSD:
17 | return R.string.license_bsd;
18 | default:
19 | return -1;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/library/src/main/java/com/danielstone/materialaboutlibrary/util/ViewTypeManager.java:
--------------------------------------------------------------------------------
1 | package com.danielstone.materialaboutlibrary.util;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | import com.danielstone.materialaboutlibrary.R;
7 | import com.danielstone.materialaboutlibrary.holders.MaterialAboutItemViewHolder;
8 | import com.danielstone.materialaboutlibrary.items.MaterialAboutItem;
9 |
10 | public abstract class ViewTypeManager {
11 |
12 | public static final class ItemType {
13 | public static final int ACTION_ITEM = 0;
14 | public static final int TITLE_ITEM = 1;
15 | }
16 |
17 | public static final class ItemLayout {
18 | public static final int ACTION_LAYOUT = R.layout.mal_material_about_action_item;
19 | public static final int TITLE_LAYOUT = R.layout.mal_material_about_title_item;
20 | }
21 |
22 | public abstract int getLayout(int itemType);
23 |
24 | public abstract MaterialAboutItemViewHolder getViewHolder(int itemType, View view);
25 |
26 | public abstract void setupItem(int itemType, MaterialAboutItemViewHolder holder, MaterialAboutItem item, Context context);
27 | }
28 |
--------------------------------------------------------------------------------
/library/src/main/res/color/mal_stroke_color.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/mal_material_about_action_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
26 |
27 |
39 |
40 |
46 |
47 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/mal_material_about_content.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/mal_material_about_list_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
24 |
25 |
29 |
30 |
42 |
43 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/mal_material_about_title_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
29 |
30 |
36 |
37 |
45 |
46 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/library/src/main/res/values-cs/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | O aplikaci
4 | Licence
5 |
6 | Zavřít
7 | Odeslat e-mail
8 |
9 | Nenalezena aplikace pro tuto akci
10 |
11 |
--------------------------------------------------------------------------------
/library/src/main/res/values-de/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Über
4 | Lizenzen
5 |
6 | Schließen
7 | E-Mail senden
8 |
9 | Keine Apps um Aktion durchzuführen
10 |
11 |
--------------------------------------------------------------------------------
/library/src/main/res/values-es/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Acerca de
4 | Licencias
5 |
6 | Cerrar
7 | Enviar email
8 |
9 | No hay apps para ejecutar esta acción
10 |
11 |
--------------------------------------------------------------------------------
/library/src/main/res/values-uk/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Про застосунок
4 | Ліцензії
5 |
6 | Закрити
7 | Надіслати e-mail
8 |
9 | Немає програм для обробки дій
10 |
11 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/library/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/library/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 16dp
6 | 8dp
7 | 4dp
8 |
9 | 24dp
10 | 32dp
11 | 40dp
12 |
13 | 2dp
14 | 1dp
15 |
16 |
17 |
--------------------------------------------------------------------------------
/library/src/main/res/values/open_source_licenses.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | "\nCopyright %1$s %2$s\n"
5 |
6 | "\nLicensed under the Apache License, Version 2.0 (the \"License\");"
7 | "you may not use this file except in compliance with the License."
8 | "You may obtain a copy of the License at\n"
9 |
10 | "\nhttp://www.apache.org/licenses/LICENSE-2.0\n"
11 |
12 | "\nUnless required by applicable law or agreed to in writing, software"
13 | "distributed under the License is distributed on an \"AS IS\" BASIS,"
14 | "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied."
15 | "See the License for the specific language governing permissions and"
16 | "limitations under the License."
17 |
18 |
19 |
20 | "\nMIT License\n"
21 |
22 | "\nCopyright © %1$s %2$s\n"
23 |
24 | "\nPermission is hereby granted, free of charge, to any person obtaining a copy"
25 | "of this software and associated documentation files (the "Software"), to deal"
26 | "in the Software without restriction, including without limitation the rights"
27 | "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell"
28 | "copies of the Software, and to permit persons to whom the Software is"
29 | "furnished to do so, subject to the following conditions:\n"
30 |
31 | "\nThe above copyright notice and this permission notice shall be included in all"
32 | "copies or substantial portions of the Software.\n"
33 |
34 | "\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR"
35 | "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,"
36 | "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE"
37 | "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER"
38 | "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,"
39 | "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE"
40 | "SOFTWARE."
41 |
42 |
43 |
44 | "\nCopyright © %1$s %2$s\n"
45 |
46 | "\nThis program is free software: you can redistribute it and/or modify"
47 | "it under the terms of the GNU General Public License as published by"
48 | "the Free Software Foundation, either version 3 of the License, or"
49 | "(at your option) any later version.\n"
50 |
51 | "\nThis program is distributed in the hope that it will be useful,"
52 | "but WITHOUT ANY WARRANTY; without even the implied warranty of"
53 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
54 | "GNU General Public License for more details.\n"
55 |
56 | "\nYou should have received a copy of the GNU General Public License"
57 | "along with this program. If not, see http://www.gnu.org/licenses.\n"
58 |
59 |
60 |
61 | "\nCopyright © %1$s %2$s\n"
62 |
63 | "\nRedistribution and use in source and binary forms, with or without"
64 | "modification, are permitted provided that the following conditions are met:\n"
65 |
66 | "\n1. Redistributions of source code must retain the above copyright notice, this"
67 | " list of conditions and the following disclaimer.\n"
68 | "2. Redistributions in binary form must reproduce the above copyright notice,"
69 | " this list of conditions and the following disclaimer in the documentation"
70 | " and/or other materials provided with the distribution.\n"
71 |
72 | "\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND"
73 | "ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED"
74 | "WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE"
75 | "DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR"
76 | "ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES"
77 | "(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;"
78 | "LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND"
79 | "ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT"
80 | "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS"
81 | "SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
82 |
83 | "\nThe views and conclusions contained in the software and documentation are those"
84 | "of the authors and should not be interpreted as representing official policies,"
85 | "either expressed or implied, of the FreeBSD Project.\n"
86 |
87 |
88 |
89 |
90 | This is free and unencumbered software released into the public domain.
91 |
92 | Anyone is free to copy, modify, publish, use, compile, sell, or
93 | distribute this software, either in source code form or as a compiled
94 | binary, for any purpose, commercial or non-commercial, and by any
95 | means.
96 |
97 | In jurisdictions that recognize copyright laws, the author or authors
98 | of this software dedicate any and all copyright interest in the
99 | software to the public domain. We make this dedication for the benefit
100 | of the public at large and to the detriment of our heirs and
101 | successors. We intend this dedication to be an overt act of
102 | relinquishment in perpetuity of all present and future rights to this
103 | software under copyright law.
104 |
105 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
106 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
107 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
108 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
109 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
110 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
111 | OTHER DEALINGS IN THE SOFTWARE.
112 |
113 | For more information, please refer to https://unlicense.org
114 |
115 |
116 |
117 |
118 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | About
4 | Licenses
5 |
6 | Close
7 | Send email
8 |
9 | No apps to handle action
10 |
11 |
--------------------------------------------------------------------------------
/library/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/screenshots/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/screenshots/1.png
--------------------------------------------------------------------------------
/screenshots/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/screenshots/2.png
--------------------------------------------------------------------------------
/screenshots/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daniel-stoneuk/material-about-library/f02ffaa20926f049cb902043f95d372a2f03d10c/screenshots/3.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------