├── .github
├── CODEOWNERS
├── FUNDING.yml
├── ISSUE_TEMPLATE
│ ├── Bug_report.md
│ └── Feature_request.md
└── pull_request_template.md
├── .gitignore
├── LICENSE
├── README.md
├── build.gradle
├── circularimageview-example
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── mikhaellopez
│ │ └── circularimageviewsample
│ │ └── MainActivity.kt
│ └── res
│ ├── drawable
│ └── logo.jpg
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── values-v21
│ └── themes.xml
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── themes.xml
├── circularimageview
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── mikhaellopez
│ │ └── circularimageview
│ │ └── CircularImageView.kt
│ └── res
│ └── values
│ └── attrs.xml
├── dependencies.gradle
├── gradle.properties
├── gradle
├── publish-mavencentral.gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── preview
├── header.png
└── preview.gif
├── publish.sh
└── settings.gradle
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # Lines starting with '#' are comments.
2 | # Each line is a file pattern followed by one or more owners.
3 |
4 | # More details are here: https://help.github.com/articles/about-codeowners/
5 |
6 | # The '*' pattern is global owners.
7 | # Not adding in this PR, but I'd like to try adding a global owner set with the entire team.
8 | # One interpretation of their docs is that global owners are added only if not removed
9 | # by a more local rule.
10 |
11 | # Order is important. The last matching pattern has the most precedence.
12 | # The folders are ordered as follows:
13 |
14 | # In each subsection folders are ordered first by depth, then alphabetically.
15 | # This should make it easy to add new rules without breaking existing ones.
16 | * @lopspower
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: lopspower
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
13 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/Bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Something is crashing or not working as intended
4 |
5 | ---
6 |
7 | **Please complete the following information:**
8 | - Library Version [e.g. v1.0.0]
9 | - Affected Device(s) [e.g. Samsung Galaxy s10 with Android 9.0]
10 |
11 | **Describe the Bug:**
12 |
13 | Add a clear description about the problem.
14 |
15 | **Expected Behavior:**
16 |
17 | A clear description of what you expected to happen.
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/Feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 |
5 | ---
6 |
7 | **Is your feature request related to a problem?**
8 |
9 | A clear and concise description of what the problem is.
10 |
11 | **Describe the solution you'd like:**
12 |
13 | A clear and concise description of what you want to happen.
14 |
15 | **Describe alternatives you've considered:**
16 |
17 | A clear description of any alternative solutions you've considered.
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 | ## Guidelines
2 | Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue.
3 |
4 | ### Types of changes
5 | What types of changes does your code introduce?
6 |
7 | - [ ] Bugfix (non-breaking change which fixes an issue)
8 | - [ ] New feature (non-breaking change which adds functionality)
9 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # GENERATED
2 | *build
3 | .gradle
4 | .DS_Store
5 |
6 | # LOCAL
7 | local.properties
8 |
9 | # IDEA
10 | *.idea
11 | *.iml
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "{}"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright 2019 LOPEZ Mikhael
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |

2 |
3 | CircularImageView
4 | =================
5 |
6 |
7 |
8 | [](http://developer.android.com/index.html)
9 | [](https://android-arsenal.com/api?level=14)
10 | [](https://search.maven.org/artifact/com.mikhaellopez/circularimageview)
11 | [](http://twitter.com/lopezmikhael)
12 |
13 | This is an Android project allowing to realize a circular ImageView in the simplest way possible.
14 |
15 |
16 |
17 |
18 |
19 | USAGE
20 | -----
21 |
22 | To make a circular ImageView add CircularImageView in your layout XML and add CircularImageView library in your project or you can also grab it via Gradle:
23 |
24 | ```groovy
25 | implementation 'com.mikhaellopez:circularimageview:4.3.1'
26 | ```
27 |
28 | XML
29 | -----
30 |
31 | ```xml
32 |
41 | ```
42 |
43 | You must use the following properties in your XML to change your CircularImageView.
44 |
45 | | Properties | Type | Default |
46 | | -------------------------------- | ------------------------------------------------------------ | ---------------- |
47 | | `app:civ_circle_color` | color | WHITE |
48 | | `app:civ_circle_color_start` | color | civ_circle_color |
49 | | `app:civ_circle_color_end` | color | civ_circle_color |
50 | | `app:civ_color_direction` | left_to_right, right_to_left, top_to_bottom or bottom_to_top | left_to_right |
51 | | `app:civ_border` | boolean | true |
52 | | `app:civ_border_width` | dimension | 4dp |
53 | | `app:civ_border_color` | color | WHITE |
54 | | `app:civ_border_color_start` | color | civ_border_color |
55 | | `app:civ_border_color_end` | color | civ_border_color |
56 | | `app:civ_border_color_direction` | left_to_right, right_to_left, top_to_bottom or bottom_to_top | left_to_right |
57 | | `app:civ_shadow` | boolean | false |
58 | | `app:civ_shadow_color` | color | BLACK |
59 | | `app:civ_shadow_radius` | dimension | 8dp |
60 | | `app:civ_shadow_gravity` | center, top, bottom, start or end | bottom |
61 |
62 | :information_source: You can also use `android:elevation` instead of `app:civ_shadow` to have default Material Design elevation.
63 |
64 | KOTLIN
65 | -----
66 |
67 | ```kotlin
68 | val circularImageView = findViewById(R.id.circularImageView)
69 | circularImageView.apply {
70 | // Set Color
71 | circleColor = Color.WHITE
72 | // or with gradient
73 | circleColorStart = Color.BLACK
74 | circleColorEnd = Color.RED
75 | circleColorDirection = CircularImageView.GradientDirection.TOP_TO_BOTTOM
76 |
77 | // Set Border
78 | borderWidth = 10f
79 | borderColor = Color.BLACK
80 | // or with gradient
81 | borderColorStart = Color.BLACK
82 | borderColorEnd = Color.RED
83 | borderColorDirection = CircularImageView.GradientDirection.TOP_TO_BOTTOM
84 |
85 | // Add Shadow with default param
86 | shadowEnable = true
87 | // or with custom param
88 | shadowRadius = 7f
89 | shadowColor = Color.RED
90 | shadowGravity = CircularImageView.ShadowGravity.CENTER
91 | }
92 | ```
93 |
94 | JAVA
95 | -----
96 |
97 | ```java
98 | CircularImageView circularImageView = findViewById(R.id.circularImageView);
99 | // Set Color
100 | circularImageView.setCircleColor(Color.WHITE);
101 | // or with gradient
102 | circularImageView.setCircleColorStart(Color.BLACK);
103 | circularImageView.setCircleColorEnd(Color.RED);
104 | circularImageView.setCircleColorDirection(CircularImageView.GradientDirection.TOP_TO_BOTTOM);
105 |
106 | // Set Border
107 | circularImageView.setBorderWidth(10f);
108 | circularImageView.setBorderColor(Color.BLACK);
109 | // or with gradient
110 | circularImageView.setBorderColorStart(Color.BLACK);
111 | circularImageView.setBorderColorEnd(Color.RED);
112 | circularImageView.setBorderColorDirection(CircularImageView.GradientDirection.TOP_TO_BOTTOM);
113 |
114 | // Add Shadow with default param
115 | circularImageView.setShadowEnable(true);
116 | // or with custom param
117 | circularImageView.setShadowRadius(7f);
118 | circularImageView.setShadowColor(Color.RED);
119 | circularImageView.setShadowGravity(CircularImageView.ShadowGravity.CENTER);
120 | ```
121 |
122 | LIMITATIONS
123 | -----
124 |
125 | - By default the ScaleType is **FIT_CENTER**. You can also used **CENTER_INSIDE** AND **CENTER_CROP**.
126 | - Enabling adjustViewBounds is not supported as this requires an unsupported ScaleType.
127 |
128 | SUPPORT ❤️
129 | -----
130 |
131 | Find this library useful? Support it by joining [**stargazers**](https://github.com/lopspower/CircularImageView/stargazers) for this repository ⭐️
132 |
133 | And [**follow me**](https://github.com/lopspower?tab=followers) for my next creations 👍
134 |
135 | LICENCE
136 | -----
137 |
138 | CircularImageView by [Lopez Mikhael](http://mikhaellopez.com/) is licensed under a [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).
139 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | apply from: 'dependencies.gradle'
3 |
4 | buildscript {
5 | ext.kotlin_version = '1.7.10'
6 | repositories {
7 | google()
8 | mavenCentral()
9 | gradlePluginPortal()
10 | }
11 | dependencies {
12 | classpath 'com.android.tools.build:gradle:7.2.2'
13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14 | classpath 'com.github.ben-manes:gradle-versions-plugin:0.42.0'
15 | }
16 | }
17 |
18 | task clean(type: Delete) {
19 | delete rootProject.buildDir
20 | }
--------------------------------------------------------------------------------
/circularimageview-example/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'org.jetbrains.kotlin.android'
4 | id 'com.github.ben-manes.versions'
5 | }
6 |
7 | android {
8 | compileSdkVersion androidCompileSdkVersion
9 | defaultConfig {
10 | applicationId "com.mikhaellopez.circularimageviewsample"
11 | minSdkVersion androidMinSdkVersion
12 | targetSdkVersion androidTargetSdkVersion
13 | versionCode 1
14 | versionName "1.0"
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | implementation project(':circularimageview')
25 | //implementation "com.mikhaellopez:circularimageview:$androidVersionName"
26 |
27 | // KOTLIN
28 | implementation kotlinStdlib
29 | // ANDROID
30 | implementation androidXAppCompat
31 | // UI
32 | implementation lobsterPicker
33 |
34 | // DEPENDENCY CHECK STRATEGY
35 | dependencyUpdates.resolutionStrategy dependencyUpdatesStrategy
36 | }
--------------------------------------------------------------------------------
/circularimageview-example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/circularimageview-example/src/main/java/com/mikhaellopez/circularimageviewsample/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.mikhaellopez.circularimageviewsample
2 |
3 | import android.os.Bundle
4 | import android.widget.SeekBar
5 | import androidx.appcompat.app.AppCompatActivity
6 | import com.larswerkman.lobsterpicker.OnColorListener
7 | import com.larswerkman.lobsterpicker.sliders.LobsterShadeSlider
8 | import com.mikhaellopez.circularimageview.CircularImageView
9 |
10 | class MainActivity : AppCompatActivity() {
11 |
12 | override fun onCreate(savedInstanceState: Bundle?) {
13 | super.onCreate(savedInstanceState)
14 | setContentView(R.layout.activity_main)
15 |
16 | val circularImageView = findViewById(R.id.circularImageView)
17 | findViewById(R.id.seekBarBorderWidth).onProgressChanged { circularImageView.borderWidth = it.toDp() }
18 | findViewById(R.id.seekBarShadowRadius).onProgressChanged { circularImageView.shadowRadius = it.toDp() }
19 | findViewById(R.id.shadeSlider).onColorChanged {
20 | circularImageView.borderColor = it
21 | circularImageView.shadowColor = it
22 | }
23 | }
24 |
25 | //region Extensions
26 | private fun Int.toDp(): Float =
27 | this * resources.displayMetrics.density
28 |
29 | private fun SeekBar.onProgressChanged(onProgressChanged: (Int) -> Unit) {
30 | setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
31 | override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
32 | onProgressChanged(progress)
33 | }
34 |
35 | override fun onStartTrackingTouch(seekBar: SeekBar?) {
36 | // Nothing
37 | }
38 |
39 | override fun onStopTrackingTouch(seekBar: SeekBar?) {
40 | // Nothing
41 | }
42 | })
43 | }
44 |
45 | private fun LobsterShadeSlider.onColorChanged(onColorChanged: (Int) -> Unit) {
46 | addOnColorListener(object : OnColorListener {
47 | override fun onColorChanged(color: Int) {
48 | onColorChanged(color)
49 | }
50 |
51 | override fun onColorSelected(color: Int) {
52 | // Nothing
53 | }
54 | })
55 | }
56 | //endregion
57 |
58 | }
--------------------------------------------------------------------------------
/circularimageview-example/src/main/res/drawable/logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopspower/CircularImageView/246752d6231033b1015c74e474f953c426b9c1c7/circularimageview-example/src/main/res/drawable/logo.jpg
--------------------------------------------------------------------------------
/circularimageview-example/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
12 |
13 |
25 |
26 |
27 |
28 |
34 |
35 |
41 |
42 |
49 |
50 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/circularimageview-example/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopspower/CircularImageView/246752d6231033b1015c74e474f953c426b9c1c7/circularimageview-example/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/circularimageview-example/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopspower/CircularImageView/246752d6231033b1015c74e474f953c426b9c1c7/circularimageview-example/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/circularimageview-example/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopspower/CircularImageView/246752d6231033b1015c74e474f953c426b9c1c7/circularimageview-example/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/circularimageview-example/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopspower/CircularImageView/246752d6231033b1015c74e474f953c426b9c1c7/circularimageview-example/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/circularimageview-example/src/main/res/values-v21/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
10 |
11 |
--------------------------------------------------------------------------------
/circularimageview-example/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #424242
4 | #212121
5 | @color/primary
6 |
--------------------------------------------------------------------------------
/circularimageview-example/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | CircularImageView
4 |
5 |
--------------------------------------------------------------------------------
/circularimageview-example/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/circularimageview/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | id 'org.jetbrains.kotlin.android'
4 | }
5 |
6 | apply from: rootProject.file('gradle/publish-mavencentral.gradle')
7 |
8 | android {
9 | compileSdkVersion androidCompileSdkVersion
10 | defaultConfig {
11 | minSdkVersion androidMinSdkVersion
12 | targetSdkVersion androidTargetSdkVersion
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | }
18 | }
19 | publishing {
20 | singleVariant('release') {
21 | withSourcesJar()
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation kotlinStdlib
28 | implementation androidXAppCompat
29 | }
30 |
--------------------------------------------------------------------------------
/circularimageview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/circularimageview/src/main/java/com/mikhaellopez/circularimageview/CircularImageView.kt:
--------------------------------------------------------------------------------
1 | package com.mikhaellopez.circularimageview
2 |
3 | import android.content.Context
4 | import android.graphics.*
5 | import android.graphics.drawable.BitmapDrawable
6 | import android.graphics.drawable.Drawable
7 | import android.graphics.drawable.VectorDrawable
8 | import android.os.Build
9 | import android.util.AttributeSet
10 | import android.view.View
11 | import android.view.ViewOutlineProvider
12 | import android.widget.ImageView.ScaleType.*
13 | import androidx.appcompat.widget.AppCompatImageView
14 | import kotlin.math.min
15 | import kotlin.math.roundToInt
16 |
17 | /**
18 | * Copyright (C) 2022 Mikhael LOPEZ
19 | * Licensed under the Apache License Version 2.0
20 | */
21 | class CircularImageView @JvmOverloads constructor(
22 | context: Context,
23 | attrs: AttributeSet? = null,
24 | defStyleAttr: Int = 0
25 | ) : AppCompatImageView(context, attrs, defStyleAttr) {
26 |
27 | companion object {
28 | private const val DEFAULT_BORDER_WIDTH = 4f
29 | private const val DEFAULT_SHADOW_RADIUS = 8.0f
30 | }
31 |
32 | // Properties
33 | private val paint: Paint = Paint().apply { isAntiAlias = true }
34 | private val paintBorder: Paint = Paint().apply { isAntiAlias = true }
35 | private val paintShadow: Paint = Paint().apply { isAntiAlias = true }
36 | private val paintBackground: Paint = Paint().apply { isAntiAlias = true }
37 | private var circleCenter = 0
38 | private var heightCircle: Int = 0
39 |
40 | //region Attributes
41 | var circleColor: Int = Color.WHITE
42 | set(value) {
43 | field = value
44 | manageCircleColor()
45 | invalidate()
46 | }
47 | var circleColorStart: Int? = null
48 | set(value) {
49 | field = value
50 | manageCircleColor()
51 | invalidate()
52 | }
53 | var circleColorEnd: Int? = null
54 | set(value) {
55 | field = value
56 | manageCircleColor()
57 | invalidate()
58 | }
59 | var circleColorDirection: GradientDirection = GradientDirection.LEFT_TO_RIGHT
60 | set(value) {
61 | field = value
62 | manageCircleColor()
63 | invalidate()
64 | }
65 | var borderWidth: Float = 0f
66 | set(value) {
67 | field = value
68 | update()
69 | }
70 | var borderColor: Int = Color.BLACK
71 | set(value) {
72 | field = value
73 | manageBorderColor()
74 | invalidate()
75 | }
76 | var borderColorStart: Int? = null
77 | set(value) {
78 | field = value
79 | manageBorderColor()
80 | invalidate()
81 | }
82 | var borderColorEnd: Int? = null
83 | set(value) {
84 | field = value
85 | manageBorderColor()
86 | invalidate()
87 | }
88 | var borderColorDirection: GradientDirection = GradientDirection.LEFT_TO_RIGHT
89 | set(value) {
90 | field = value
91 | manageBorderColor()
92 | invalidate()
93 | }
94 | var shadowRadius: Float = 0f
95 | set(value) {
96 | field = value
97 | shadowEnable = shadowRadius > 0f
98 | }
99 | var shadowColor = Color.BLACK
100 | set(value) {
101 | field = value
102 | paintShadow.color = field
103 | invalidate()
104 | }
105 | var shadowGravity = ShadowGravity.BOTTOM
106 | set(value) {
107 | field = value
108 | invalidate()
109 | }
110 | var shadowEnable = false
111 | set(value) {
112 | field = value
113 | if (field && shadowRadius == 0f) {
114 | shadowRadius = DEFAULT_SHADOW_RADIUS * resources.displayMetrics.density
115 | }
116 | update()
117 | }
118 | //endregion
119 |
120 | // Color Filter
121 | private var civColorFilter: ColorFilter? = null
122 | set(value) {
123 | if (field != value) {
124 | field = value
125 | if (field != null) {
126 | civDrawable = null // To force re-update shader
127 | invalidate()
128 | }
129 | }
130 | }
131 |
132 | // Object used to draw
133 | private var civImage: Bitmap? = null
134 | private var civDrawable: Drawable? = null
135 |
136 | init {
137 | init(context, attrs, defStyleAttr)
138 | }
139 |
140 | private fun init(context: Context, attrs: AttributeSet?, defStyleAttr: Int) {
141 | // Load the styled attributes and set their properties
142 | val attributes =
143 | context.obtainStyledAttributes(attrs, R.styleable.CircularImageView, defStyleAttr, 0)
144 |
145 | // Init Background Color
146 | circleColor =
147 | attributes.getColor(R.styleable.CircularImageView_civ_circle_color, Color.WHITE)
148 | attributes.getColor(R.styleable.CircularImageView_civ_circle_color_start, 0)
149 | .also { if (it != 0) circleColorStart = it }
150 | attributes.getColor(R.styleable.CircularImageView_civ_circle_color_end, 0)
151 | .also { if (it != 0) circleColorEnd = it }
152 | circleColorDirection = attributes.getInteger(
153 | R.styleable.CircularImageView_civ_circle_color_direction,
154 | circleColorDirection.value
155 | ).toGradientDirection()
156 |
157 | // Init Border
158 | if (attributes.getBoolean(R.styleable.CircularImageView_civ_border, true)) {
159 | val defaultBorderWidth =
160 | DEFAULT_BORDER_WIDTH * resources.displayMetrics.density
161 | borderWidth = attributes.getDimension(
162 | R.styleable.CircularImageView_civ_border_width,
163 | defaultBorderWidth
164 | )
165 | borderColor =
166 | attributes.getColor(R.styleable.CircularImageView_civ_border_color, Color.WHITE)
167 | attributes.getColor(R.styleable.CircularImageView_civ_border_color_start, 0)
168 | .also { if (it != 0) borderColorStart = it }
169 | attributes.getColor(R.styleable.CircularImageView_civ_border_color_end, 0)
170 | .also { if (it != 0) borderColorEnd = it }
171 | borderColorDirection = attributes.getInteger(
172 | R.styleable.CircularImageView_civ_border_color_direction,
173 | borderColorDirection.value
174 | ).toGradientDirection()
175 | }
176 |
177 | // Init Shadow
178 | shadowEnable = attributes.getBoolean(R.styleable.CircularImageView_civ_shadow, shadowEnable)
179 | if (shadowEnable) {
180 | shadowGravity = attributes.getInteger(
181 | R.styleable.CircularImageView_civ_shadow_gravity,
182 | shadowGravity.value
183 | ).toShadowGravity()
184 | val defaultShadowRadius = DEFAULT_SHADOW_RADIUS * resources.displayMetrics.density
185 | shadowRadius = attributes.getDimension(
186 | R.styleable.CircularImageView_civ_shadow_radius,
187 | defaultShadowRadius
188 | )
189 | shadowColor =
190 | attributes.getColor(R.styleable.CircularImageView_civ_shadow_color, shadowColor)
191 | }
192 |
193 | attributes.recycle()
194 | }
195 | //endregion
196 |
197 | //region Set Attr Method
198 | override fun setColorFilter(colorFilter: ColorFilter?) {
199 | civColorFilter = colorFilter
200 | }
201 |
202 | override fun getScaleType(): ScaleType =
203 | super.getScaleType() ?: CENTER_CROP
204 |
205 | override fun setScaleType(scaleType: ScaleType) {
206 | require(
207 | listOf(
208 | CENTER_CROP,
209 | CENTER_INSIDE,
210 | FIT_CENTER
211 | ).contains(scaleType)
212 | ) {
213 | "ScaleType $scaleType not supported. Just ScaleType.CENTER_CROP, ScaleType.CENTER_INSIDE & ScaleType.FIT_CENTER are available for this library."
214 | }
215 | super.setScaleType(scaleType)
216 | }
217 | //endregion
218 |
219 | //region Draw Method
220 | override fun onDraw(canvas: Canvas) {
221 | // Load the bitmap
222 | loadBitmap()
223 |
224 | // Check if civImage isn't null
225 | if (civImage == null) return
226 |
227 | val circleCenterWithBorder = circleCenter + borderWidth
228 | val margeWithShadowRadius = if (shadowEnable) shadowRadius * 2 else 0f
229 |
230 | // Draw Shadow
231 | if (shadowEnable) {
232 | drawShadow()
233 | canvas.drawCircle(
234 | circleCenterWithBorder,
235 | circleCenterWithBorder,
236 | circleCenterWithBorder - margeWithShadowRadius,
237 | paintShadow
238 | )
239 | }
240 | // Draw Border
241 | canvas.drawCircle(
242 | circleCenterWithBorder,
243 | circleCenterWithBorder,
244 | circleCenterWithBorder - margeWithShadowRadius,
245 | paintBorder
246 | )
247 | // Draw Circle background
248 | canvas.drawCircle(
249 | circleCenterWithBorder,
250 | circleCenterWithBorder,
251 | circleCenter - margeWithShadowRadius,
252 | paintBackground
253 | )
254 | // Draw CircularImageView
255 | canvas.drawCircle(
256 | circleCenterWithBorder,
257 | circleCenterWithBorder,
258 | circleCenter - margeWithShadowRadius,
259 | paint
260 | )
261 | }
262 |
263 | private fun update() {
264 | if (civImage != null)
265 | updateShader()
266 |
267 | val usableWidth = width - (paddingLeft + paddingRight)
268 | val usableHeight = height - (paddingTop + paddingBottom)
269 |
270 | heightCircle = min(usableWidth, usableHeight)
271 |
272 | circleCenter = (heightCircle - borderWidth * 2).toInt() / 2
273 | manageCircleColor()
274 | manageBorderColor()
275 |
276 | manageElevation()
277 | invalidate()
278 | }
279 |
280 | private fun manageCircleColor() {
281 | paintBackground.shader = createLinearGradient(
282 | circleColorStart ?: circleColor,
283 | circleColorEnd ?: circleColor, circleColorDirection
284 | )
285 | }
286 |
287 | private fun manageBorderColor() {
288 | val borderColor = if (borderWidth == 0f) circleColor else this.borderColor
289 | paintBorder.shader = createLinearGradient(
290 | borderColorStart ?: borderColor,
291 | borderColorEnd ?: borderColor, borderColorDirection
292 | )
293 | }
294 |
295 | private fun createLinearGradient(
296 | startColor: Int,
297 | endColor: Int,
298 | gradientDirection: GradientDirection
299 | ): LinearGradient {
300 | var x0 = 0f
301 | var y0 = 0f
302 | var x1 = 0f
303 | var y1 = 0f
304 | when (gradientDirection) {
305 | GradientDirection.LEFT_TO_RIGHT -> x1 = width.toFloat()
306 | GradientDirection.RIGHT_TO_LEFT -> x0 = width.toFloat()
307 | GradientDirection.TOP_TO_BOTTOM -> y1 = height.toFloat()
308 | GradientDirection.BOTTOM_TO_TOP -> y0 = height.toFloat()
309 | }
310 | return LinearGradient(x0, y0, x1, y1, startColor, endColor, Shader.TileMode.CLAMP)
311 | }
312 |
313 | private fun manageElevation() {
314 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
315 | outlineProvider = if (!shadowEnable) object : ViewOutlineProvider() {
316 | override fun getOutline(view: View?, outline: Outline?) {
317 | outline?.setOval(0, 0, heightCircle, heightCircle)
318 | }
319 | } else {
320 | null
321 | }
322 | }
323 | }
324 |
325 | private fun loadBitmap() {
326 | if (civDrawable == drawable) return
327 |
328 | civDrawable = drawable
329 | civImage = drawableToBitmap(civDrawable)
330 | updateShader()
331 | }
332 |
333 | override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
334 | super.onSizeChanged(w, h, oldw, oldh)
335 | update()
336 | }
337 |
338 | private fun drawShadow() {
339 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
340 | setLayerType(View.LAYER_TYPE_SOFTWARE, paintShadow)
341 | }
342 |
343 | var dx = 0.0f
344 | var dy = 0.0f
345 |
346 | when (shadowGravity) {
347 | ShadowGravity.CENTER -> {
348 | /*dx, dy = 0.0f*/
349 | }
350 | ShadowGravity.TOP -> dy = -shadowRadius / 2
351 | ShadowGravity.BOTTOM -> dy = shadowRadius / 2
352 | ShadowGravity.START -> dx = -shadowRadius / 2
353 | ShadowGravity.END -> dx = shadowRadius / 2
354 | }
355 |
356 | paintShadow.setShadowLayer(shadowRadius, dx, dy, shadowColor)
357 | }
358 |
359 | private fun updateShader() {
360 | civImage?.also {
361 | // Create Shader
362 | val shader = BitmapShader(it, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
363 |
364 | // Apply matrix in Shader with scaleType
365 | shader.setLocalMatrix(
366 | when (scaleType) {
367 | CENTER_CROP -> centerCrop(it, heightCircle)
368 | CENTER_INSIDE -> centerInside(it, heightCircle)
369 | FIT_CENTER -> fitCenter(it, heightCircle)
370 | else -> Matrix()
371 | }
372 | )
373 |
374 | // Set Shader in Paint
375 | paint.shader = shader
376 |
377 | // Apply colorFilter
378 | paint.colorFilter = civColorFilter
379 | }
380 | }
381 |
382 | private fun centerCrop(bitmap: Bitmap, viewSize: Int): Matrix =
383 | Matrix().apply {
384 | val scale: Float
385 | val dx: Float
386 | val dy: Float
387 | if (bitmap.width * viewSize > bitmap.height * viewSize) {
388 | scale = viewSize / bitmap.height.toFloat()
389 | dx = (viewSize - bitmap.width * scale) * .5f
390 | dy = 0f
391 | } else {
392 | scale = viewSize / bitmap.width.toFloat()
393 | dx = 0f
394 | dy = (viewSize - bitmap.height * scale) * .5f
395 | }
396 | setScale(scale, scale)
397 | postTranslate(dx, dy)
398 | }
399 |
400 | private fun centerInside(bitmap: Bitmap, viewSize: Int): Matrix =
401 | Matrix().apply {
402 | val scale = if (bitmap.width <= viewSize && bitmap.height <= viewSize) {
403 | 1.0f
404 | } else {
405 | (viewSize.toFloat() / bitmap.width.toFloat()).coerceAtMost(viewSize.toFloat() / bitmap.height.toFloat())
406 | }
407 |
408 | val dx: Float = ((viewSize - bitmap.width * scale) * .5f).roundToInt().toFloat()
409 | val dy: Float = ((viewSize - bitmap.height * scale) * .5f).roundToInt().toFloat()
410 |
411 | setScale(scale, scale)
412 | postTranslate(dx, dy)
413 | }
414 |
415 | private fun fitCenter(bitmap: Bitmap, viewSize: Int): Matrix =
416 | Matrix().apply {
417 | setRectToRect(
418 | RectF().apply { set(0f, 0f, bitmap.width.toFloat(), bitmap.height.toFloat()) },
419 | RectF().apply { set(0f, 0f, viewSize.toFloat(), viewSize.toFloat()) },
420 | Matrix.ScaleToFit.CENTER
421 | )
422 | }
423 |
424 | private fun drawableToBitmap(drawable: Drawable?): Bitmap? =
425 | drawable?.let {
426 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && drawable is VectorDrawable) {
427 | drawable.vectorDrawableToBitmap()
428 | } else {
429 | when (drawable) {
430 | is BitmapDrawable -> drawable.bitmapDrawableToBitmap()
431 | else -> drawable.toBitmap()
432 | }
433 | }
434 | }
435 |
436 | private fun VectorDrawable.vectorDrawableToBitmap(): Bitmap {
437 | // Generate max bitmap size from view when is vector drawable
438 | // no when scale type is CENTER_INSIDE
439 | val bitmap = Bitmap.createBitmap(
440 | if (scaleType == CENTER_INSIDE) this.intrinsicWidth else width,
441 | if (scaleType == CENTER_INSIDE) this.intrinsicHeight else height,
442 | Bitmap.Config.ARGB_8888
443 | )
444 | val canvas = Canvas(bitmap)
445 | this.setBounds(0, 0, canvas.width, canvas.height)
446 | this.draw(canvas)
447 | return bitmap
448 | }
449 |
450 | private fun BitmapDrawable.bitmapDrawableToBitmap(): Bitmap =
451 | bitmap.let {
452 | Bitmap.createScaledBitmap(
453 | it,
454 | this.intrinsicWidth,
455 | this.intrinsicHeight,
456 | false
457 | )
458 | }
459 |
460 | private fun Drawable.toBitmap(): Bitmap? =
461 | try {
462 | // Create Bitmap object out of the drawable
463 | val bitmap = Bitmap.createBitmap(
464 | this.intrinsicWidth,
465 | this.intrinsicHeight,
466 | Bitmap.Config.ARGB_8888
467 | )
468 | val canvas = Canvas(bitmap)
469 | this.setBounds(0, 0, canvas.width, canvas.height)
470 | this.draw(canvas)
471 | bitmap
472 | } catch (e: Exception) {
473 | e.printStackTrace()
474 | null
475 | }
476 | //endregion
477 |
478 | //region Measure Method
479 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
480 | val usableWidth = measure(widthMeasureSpec) - (paddingLeft + paddingRight)
481 | val usableHeight = measure(heightMeasureSpec) - (paddingTop + paddingBottom)
482 | heightCircle = min(usableWidth, usableHeight)
483 | setMeasuredDimension(heightCircle, heightCircle)
484 | }
485 |
486 | private fun measure(measureSpec: Int): Int {
487 | val specMode = MeasureSpec.getMode(measureSpec)
488 | val specSize = MeasureSpec.getSize(measureSpec)
489 | return when (specMode) {
490 | MeasureSpec.EXACTLY -> specSize // The parent has determined an exact size for the child.
491 | MeasureSpec.AT_MOST -> specSize // The child can be as large as it wants up to the specified size.
492 | else -> heightCircle // The parent has not imposed any constraint on the child.
493 | }
494 | }
495 | //endregion
496 |
497 | private fun Int.toShadowGravity(): ShadowGravity =
498 | when (this) {
499 | 1 -> ShadowGravity.CENTER
500 | 2 -> ShadowGravity.TOP
501 | 3 -> ShadowGravity.BOTTOM
502 | 4 -> ShadowGravity.START
503 | 5 -> ShadowGravity.END
504 | else -> throw IllegalArgumentException("This value is not supported for ShadowGravity: $this")
505 | }
506 |
507 | private fun Int.toGradientDirection(): GradientDirection =
508 | when (this) {
509 | 1 -> GradientDirection.LEFT_TO_RIGHT
510 | 2 -> GradientDirection.RIGHT_TO_LEFT
511 | 3 -> GradientDirection.TOP_TO_BOTTOM
512 | 4 -> GradientDirection.BOTTOM_TO_TOP
513 | else -> throw IllegalArgumentException("This value is not supported for GradientDirection: $this")
514 | }
515 |
516 | /**
517 | * ShadowGravity enum class to set the gravity of the CircleView shadow
518 | */
519 | enum class ShadowGravity(val value: Int) {
520 | CENTER(1),
521 | TOP(2),
522 | BOTTOM(3),
523 | START(4),
524 | END(5)
525 | }
526 |
527 | /**
528 | * GradientDirection enum class to set the direction of the gradient color
529 | */
530 | enum class GradientDirection(val value: Int) {
531 | LEFT_TO_RIGHT(1),
532 | RIGHT_TO_LEFT(2),
533 | TOP_TO_BOTTOM(3),
534 | BOTTOM_TO_TOP(4)
535 | }
536 |
537 | }
--------------------------------------------------------------------------------
/circularimageview/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/dependencies.gradle:
--------------------------------------------------------------------------------
1 | allprojects {
2 | repositories {
3 | google()
4 | mavenCentral()
5 | }
6 | }
7 |
8 | ext {
9 | // LIBRARY VERSION
10 | androidVersionCode = 20
11 | androidVersionName = "4.3.1"
12 |
13 | // LIBRARY INFORMATION
14 | libraryGroupId = 'com.mikhaellopez'
15 | libraryArtifactId = 'circularimageview'
16 | libraryVersion = androidVersionName
17 | libraryName = "CircularImageView"
18 | libraryDesc = "This is an Android project allowing to realize a circular ImageView in the simplest way possible."
19 |
20 | // ANDROID VERSION
21 | androidCompileSdkVersion = 33
22 | androidMinSdkVersion = 14
23 | androidTargetSdkVersion = 33
24 |
25 | // KOTLIN
26 | kotlinStdlib = "org.jetbrains.kotlin:kotlin-stdlib:$ext.kotlin_version"
27 |
28 | // ANDROID LIB
29 | androidXAppCompat = "androidx.appcompat:appcompat:1.5.0"
30 |
31 | // UI
32 | lobsterPicker = "com.larswerkman:lobsterpicker:1.0.1"
33 |
34 | // DEPENDENCY CHECK STRATEGY
35 | dependencyUpdatesStrategy = {
36 | def isNonStable = { String version ->
37 | def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { keyword ->
38 | version.toUpperCase().contains(keyword)
39 | }
40 | def regex = /^[0-9,.v-]+(-r)?$/
41 | return !stableKeyword && !(version ==~ regex)
42 | }
43 | componentSelection {
44 | all {
45 | if (isNonStable(it.candidate.version) && !isNonStable(it.currentVersion)) {
46 | reject('Release candidate')
47 | }
48 | }
49 | }
50 | }
51 |
52 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # Gradle
4 | # Specifies the JVM arguments used for the daemon process.
5 | # The setting is particularly useful for tweaking memory settings.
6 | org.gradle.jvmargs=-Xmx3072m
7 |
8 | # Kotlin
9 | # Kotlin code style for this project: "official" or "obsolete":
10 | kotlin.code.style=official
11 |
12 | # Android
13 | # When set to true, this flag indicates that you want to start using AndroidX from now on.
14 | # If the flag is absent, Android Studio behaves as if the flag were set to false.
15 | android.useAndroidX=true
16 | # When set to true, this flag indicates that you want to have tool support (from the Android Gradle
17 | # plugin) to automatically convert existing third-party libraries as if they were written for
18 | # AndroidX. If the flag is absent, Android Studio behaves as if the flag were set to false.
19 | android.enableJetifier=true
--------------------------------------------------------------------------------
/gradle/publish-mavencentral.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'maven-publish'
2 | apply plugin: 'signing'
3 |
4 | afterEvaluate {
5 | publishing {
6 | publications {
7 | release(MavenPublication) {
8 | groupId = libraryGroupId
9 | artifactId = libraryArtifactId
10 | version = libraryVersion
11 |
12 | from components.release
13 |
14 | pom {
15 | name = libraryName
16 | packaging = 'aar'
17 | description = libraryDesc
18 | url = "https://github.com/lopspower/$libraryName"
19 |
20 | scm {
21 | connection = "scm:git:https://github.com/lopspower/$libraryName"
22 | developerConnection = "scm:git:https://github.com/lopspower/$libraryName"
23 | url = "https://github.com/lopspower/$libraryName"
24 | }
25 | licenses {
26 | license {
27 | name = 'The Apache Software License, Version 2.0'
28 | url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
29 | }
30 | }
31 | developers {
32 | developer {
33 | id = 'lopspower'
34 | name = 'Mikhael LOPEZ'
35 | email = 'lopez.mikhael@gmail.com'
36 | url = 'https://github.com/lopspower'
37 | }
38 | }
39 | }
40 | }
41 | }
42 | repositories {
43 | maven {
44 | name = "ossrh"
45 | url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
46 | credentials {
47 | username = ossrhUsername
48 | password = ossrhPassword
49 | }
50 | }
51 | }
52 | }
53 | }
54 |
55 | signing {
56 | sign publishing.publications
57 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopspower/CircularImageView/246752d6231033b1015c74e474f953c426b9c1c7/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Aug 22 09:37:12 CEST 2019
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-7.5.1-all.zip
--------------------------------------------------------------------------------
/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 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/preview/header.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopspower/CircularImageView/246752d6231033b1015c74e474f953c426b9c1c7/preview/header.png
--------------------------------------------------------------------------------
/preview/preview.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopspower/CircularImageView/246752d6231033b1015c74e474f953c426b9c1c7/preview/preview.gif
--------------------------------------------------------------------------------
/publish.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | ./gradlew clean
3 | ./gradlew publish
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':circularimageview-example', ':circularimageview'
2 |
--------------------------------------------------------------------------------