├── .github
└── FUNDING.yml
├── .gitignore
├── DEV
├── icon
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ │ └── ic_launcher.png
│ ├── drawable-xxxhdpi
│ │ └── ic_launcher.png
│ └── icon_512.png
├── icon_new
│ ├── badge.png
│ ├── res
│ │ ├── drawable-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xxhdpi
│ │ │ └── ic_launcher.png
│ │ └── drawable-xxxhdpi
│ │ │ └── ic_launcher.png
│ ├── web_hi_res_512.png
│ └── web_hi_res_512_trimmed.png
└── screenshot
│ ├── screenshot1.png
│ ├── screenshot1_small.png
│ ├── screenshot2.png
│ └── screenshot2_small.png
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── mikepenz
│ │ └── actionitembadge
│ │ └── sample
│ │ ├── MainActivity.java
│ │ └── ToolbarActivity.java
│ └── res
│ ├── drawable-hdpi
│ ├── ic_launcher.png
│ └── ic_notification.png
│ ├── drawable-mdpi
│ ├── ic_launcher.png
│ └── ic_notification.png
│ ├── drawable-xhdpi
│ ├── ic_launcher.png
│ └── ic_notification.png
│ ├── drawable-xxhdpi
│ ├── ic_launcher.png
│ └── ic_notification.png
│ ├── drawable-xxxhdpi
│ ├── ic_launcher.png
│ └── ic_notification.png
│ ├── layout
│ ├── activity_main.xml
│ └── activity_toolbar_main.xml
│ ├── menu
│ └── main.xml
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── aboutlibraries.xml
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle-release.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── gradle.properties
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── mikepenz
│ │ └── actionitembadge
│ │ └── library
│ │ ├── ActionItemBadge.java
│ │ ├── ActionItemBadgeAdder.java
│ │ └── utils
│ │ ├── BadgeDrawableBuilder.java
│ │ ├── BadgeStyle.java
│ │ ├── NumberUtils.java
│ │ └── UIUtil.java
│ └── res
│ ├── drawable
│ └── action_item_badge.xml
│ ├── layout
│ ├── menu_action_item_badge.xml
│ └── menu_action_item_badge_large.xml
│ └── values
│ └── aboutlibraries.xml
└── settings.gradle
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: [mikepenz]
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Android Studio
26 | .idea
27 | *.iml
--------------------------------------------------------------------------------
/DEV/icon/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/DEV/icon/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DEV/icon/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/DEV/icon/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DEV/icon/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/DEV/icon/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DEV/icon/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/DEV/icon/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DEV/icon/drawable-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/DEV/icon/drawable-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DEV/icon/icon_512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/DEV/icon/icon_512.png
--------------------------------------------------------------------------------
/DEV/icon_new/badge.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/DEV/icon_new/badge.png
--------------------------------------------------------------------------------
/DEV/icon_new/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/DEV/icon_new/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DEV/icon_new/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/DEV/icon_new/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DEV/icon_new/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/DEV/icon_new/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DEV/icon_new/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/DEV/icon_new/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DEV/icon_new/res/drawable-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/DEV/icon_new/res/drawable-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DEV/icon_new/web_hi_res_512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/DEV/icon_new/web_hi_res_512.png
--------------------------------------------------------------------------------
/DEV/icon_new/web_hi_res_512_trimmed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/DEV/icon_new/web_hi_res_512_trimmed.png
--------------------------------------------------------------------------------
/DEV/screenshot/screenshot1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/DEV/screenshot/screenshot1.png
--------------------------------------------------------------------------------
/DEV/screenshot/screenshot1_small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/DEV/screenshot/screenshot1_small.png
--------------------------------------------------------------------------------
/DEV/screenshot/screenshot2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/DEV/screenshot/screenshot2.png
--------------------------------------------------------------------------------
/DEV/screenshot/screenshot2_small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/DEV/screenshot/screenshot2_small.png
--------------------------------------------------------------------------------
/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.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android-ActionItemBadge [](https://maven-badges.herokuapp.com/maven-central/com.mikepenz/actionitembadge) [](http://android-arsenal.com/details/1/755)
2 |
3 | [](https://gitter.im/mikepenz/Android-ActionItemBadge?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4 |
5 | ActionItemBadge is a library which offers a simple and easy to use method to add a badge to your action item!
6 |
7 | ## Screenshots
8 | 
9 | 
10 |
11 | ## Include in your project
12 | ### Using Maven
13 | The ActionItemBadge Library is pushed to [Maven Central], so you just need to add the following dependency to your `build.gradle`.
14 |
15 | ```javascript
16 | dependencies {
17 | implementation 'com.mikepenz:actionitembadge:4.0.0'
18 |
19 | //SUB-DEPENDENCIES
20 | //Android-Iconics - used to provide an easy API for icons
21 | implementation 'com.mikepenz:iconics-core:{latestVersion}@aar'
22 | }
23 | ```
24 |
25 | ### Additional dependency for the icon font
26 | If you are going to use the icon font you will have to add additional dependency for the font.
27 | You can find all available addons here: https://github.com/mikepenz/Android-Iconics#2-choose-your-desired-fonts
28 |
29 | ## UPGRADE NOTES
30 | #### < 4.0.0
31 | - If you come from a version prior 4.0.0 you will have to upgrade to AndroidX and Iconics v4
32 |
33 | #### < 3.0.0
34 | - If you come from a version prior 3.0.0 you will have to rename some classes, and the default styles also found a new place. Just check out the updated sample app for all the changes.
35 |
36 | ## Usage
37 | ### menu.xml
38 | Create your menu.xml as you would do normally and add the app:actionLayout param.
39 | It is also a good idea to set showAsAction="always" (The badge can only be shown in the actionbar)
40 | ```xml
41 |
50 | ```
51 | ### Activity
52 | Override the onCreateOptionsMenu method
53 | ```java
54 | @Override
55 | public boolean onCreateOptionsMenu(Menu menu) {
56 | // Inflate the menu; this adds items to the action bar if it is present.
57 | getMenuInflater().inflate(R.menu.main, menu);
58 |
59 | //you can add some logic (hide it if the count == 0)
60 | if (badgeCount > 0) {
61 | ActionItemBadge.update(this, menu.findItem(R.id.item_samplebadge), FontAwesome.Icon.faw_android, ActionItemBadge.BadgeStyles.DARK_GREY, badgeCount);
62 | } else {
63 | ActionItemBadge.hide(menu.findItem(R.id.item_samplebadge));
64 | }
65 |
66 | //If you want to add your ActionItem programmatically you can do this too. You do the following:
67 | new ActionItemBadgeAdder().act(this).menu(menu).title(R.string.sample_2).itemDetails(0, SAMPLE2_ID, 1).showAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS).add(bigStyle, 1);
68 | return super.onCreateOptionsMenu(menu);
69 | }
70 | ```
71 |
72 | If you want to update the item itself you can do the required stuff in the onOptionsItemSelected method and
73 | call invalidateOptionsMenu() afterwards.
74 | ```java
75 | @Override
76 | public boolean onOptionsItemSelected(MenuItem item) {
77 | int id = item.getItemId();
78 | if (id == R.id.item_samplebadge) {
79 | Toast.makeText(this, R.string.sample_3, Toast.LENGTH_SHORT).show();
80 | badgeCount--;
81 | ActionItemBadge.update(item, badgeCount);
82 | return true;
83 | } else if (id == SAMPLE2_ID) {
84 | Toast.makeText(this, R.string.sample_4, Toast.LENGTH_SHORT).show();
85 | }
86 | return super.onOptionsItemSelected(item);
87 | }
88 | ```
89 |
90 | # Dependencies
91 | * Android-Iconics - https://github.com/mikepenz/Android-Iconics
92 |
93 |
94 | # Developed By
95 |
96 | * Mike Penz
97 | * [mikepenz.com](http://mikepenz.com) -
98 | * [paypal.me/mikepenz](http://paypal.me/mikepenz)
99 |
100 | # License
101 |
102 | Copyright 2019 Mike Penz
103 |
104 | Licensed under the Apache License, Version 2.0 (the "License");
105 | you may not use this file except in compliance with the License.
106 | You may obtain a copy of the License at
107 |
108 | http://www.apache.org/licenses/LICENSE-2.0
109 |
110 | Unless required by applicable law or agreed to in writing, software
111 | distributed under the License is distributed on an "AS IS" BASIS,
112 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
113 | See the License for the specific language governing permissions and
114 | limitations under the License.
115 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | //wrap with try and catch so the build is working even if the signing stuff is missing
6 | try {
7 | apply from: '../../../signing.gradle'
8 | } catch (ex) {
9 | }
10 |
11 | android {
12 | compileSdkVersion setup.compileSdk
13 | buildToolsVersion setup.buildTools
14 |
15 | defaultConfig {
16 | minSdkVersion setup.minSdk
17 | targetSdkVersion setup.targetSdk
18 | versionCode release.versionCode
19 | versionName release.versionName
20 |
21 | multiDexEnabled true
22 |
23 | setProperty("archivesBaseName", "ActionItemBadge-v$versionName-c$versionCode")
24 | }
25 | buildTypes {
26 | debug {
27 | versionNameSuffix "-DEBUG"
28 | try {
29 | signingConfig signingConfigs.debug
30 | } catch (ex) {
31 | }
32 | minifyEnabled false
33 | }
34 | release {
35 | try {
36 | signingConfig signingConfigs.release
37 | } catch (ex) {
38 | }
39 | zipAlignEnabled true
40 | minifyEnabled false
41 | }
42 | }
43 |
44 | lintOptions {
45 | abortOnError false
46 | }
47 | }
48 |
49 | dependencies {
50 | implementation project(':library')
51 |
52 | implementation "androidx.appcompat:appcompat:${versions.appcompat}"
53 | implementation "androidx.recyclerview:recyclerview:${versions.recyclerView}"
54 | implementation "androidx.cardview:cardview:${versions.cardview}"
55 |
56 | // used to base on some backwards compatible themes
57 | // contains util classes to support various android versions, and clean up code
58 | // comes with the awesome "Holder"-Pattern
59 | // https://github.com/mikepenz/Materialize
60 | implementation "com.mikepenz:materialize:${versions.materialize}"
61 |
62 | // used to fill the RecyclerView with the DrawerItems
63 | // and provides single and multi selection, expandable items
64 | // https://github.com/mikepenz/FastAdapter
65 | implementation "com.mikepenz:fastadapter:${versions.fastadapter}"
66 |
67 | // used to provide out of the box icon font support. simplifies development,
68 | // and provides scalable icons. the core is very very light
69 | // https://github.com/mikepenz/Android-Iconics
70 | implementation "com.mikepenz:iconics-core:${versions.iconics}"
71 | implementation "com.mikepenz:iconics-views:${versions.iconics}"
72 |
73 | //used to generate the drawer on the left
74 | //https://github.com/mikepenz/MaterialDrawer
75 | implementation "com.mikepenz:materialdrawer:${versions.materialdrawer}"
76 |
77 | //used to generate the Open Source section
78 | //https://github.com/mikepenz/AboutLibraries
79 | implementation "com.mikepenz:aboutlibraries:${versions.aboutlib}"
80 |
81 | //used to display the icons in the drawer and in the menu
82 | //https://github.com/mikepenz/Android-Iconics
83 | implementation 'com.mikepenz:google-material-typeface:3.0.1.4.original-kotlin@aar'
84 | implementation 'com.mikepenz:fontawesome-typeface:5.9.0.0-kotlin@aar'
85 | implementation 'com.mikepenz:crossfader:1.6.0@aar'
86 | }
87 |
--------------------------------------------------------------------------------
/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 /Entwicklung/android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mikepenz/actionitembadge/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.mikepenz.actionitembadge.sample;
2 |
3 | import android.os.Bundle;
4 | import android.view.Menu;
5 | import android.view.MenuItem;
6 | import android.widget.Toast;
7 |
8 | import androidx.appcompat.app.ActionBar;
9 | import androidx.appcompat.app.AppCompatActivity;
10 | import androidx.fragment.app.FragmentManager;
11 |
12 | import com.mikepenz.aboutlibraries.LibsBuilder;
13 | import com.mikepenz.aboutlibraries.ui.LibsSupportFragment;
14 | import com.mikepenz.actionitembadge.R;
15 | import com.mikepenz.actionitembadge.library.ActionItemBadge;
16 | import com.mikepenz.actionitembadge.library.ActionItemBadgeAdder;
17 | import com.mikepenz.iconics.typeface.library.fontawesome.FontAwesome;
18 |
19 |
20 | public class MainActivity extends AppCompatActivity {
21 | private int badgeCount = 10;
22 |
23 | private static final int SAMPLE2_ID = 34535;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_main);
29 |
30 | ActionBar ab = getSupportActionBar();
31 | if (ab != null) {
32 | ab.setDisplayUseLogoEnabled(true);
33 | ab.setTitle("");
34 | ab.show();
35 | }
36 |
37 | //init and show about libraries :D
38 | LibsSupportFragment fragment = new LibsBuilder().withFields(R.string.class.getFields()).withVersionShown(true).withLicenseShown(true).supportFragment();
39 | FragmentManager fragmentManager = getSupportFragmentManager();
40 | fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();
41 | }
42 |
43 |
44 | @Override
45 | public boolean onCreateOptionsMenu(Menu menu) {
46 | // Inflate the menu; this adds items to the action bar if it is present.
47 | getMenuInflater().inflate(R.menu.main, menu);
48 |
49 | if (badgeCount > 0) {
50 | ActionItemBadge.update(this, menu.findItem(R.id.item_samplebadge), FontAwesome.Icon.faw_android, ActionItemBadge.BadgeStyles.GREY, badgeCount);
51 | } else {
52 | ActionItemBadge.hide(menu.findItem(R.id.item_samplebadge));
53 | }
54 |
55 | new ActionItemBadgeAdder().act(this).menu(menu).title(R.string.sample_2).itemDetails(0, SAMPLE2_ID, 1).showAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS).add(ActionItemBadge.BadgeStyles.GREY_LARGE, 1);
56 | return true;
57 | }
58 |
59 | @Override
60 | public boolean onOptionsItemSelected(MenuItem item) {
61 | // Handle action bar item clicks here. The action bar will
62 | // automatically handle clicks on the Home/Up button, so long
63 | // as you specify a parent activity in AndroidManifest.xml.
64 | int id = item.getItemId();
65 | if (id == R.id.item_samplebadge) {
66 | Toast.makeText(this, R.string.sample_3, Toast.LENGTH_SHORT).show();
67 | badgeCount--;
68 | invalidateOptionsMenu();
69 | return true;
70 | } else if (id == SAMPLE2_ID) {
71 | Toast.makeText(this, R.string.sample_4, Toast.LENGTH_SHORT).show();
72 | }
73 | return super.onOptionsItemSelected(item);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/java/com/mikepenz/actionitembadge/sample/ToolbarActivity.java:
--------------------------------------------------------------------------------
1 | package com.mikepenz.actionitembadge.sample;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 | import android.view.View;
9 | import android.widget.Toast;
10 |
11 | import androidx.appcompat.app.AppCompatActivity;
12 | import androidx.appcompat.widget.Toolbar;
13 | import androidx.core.content.ContextCompat;
14 | import androidx.fragment.app.FragmentManager;
15 |
16 | import com.mikepenz.aboutlibraries.LibsBuilder;
17 | import com.mikepenz.aboutlibraries.ui.LibsSupportFragment;
18 | import com.mikepenz.actionitembadge.R;
19 | import com.mikepenz.actionitembadge.library.ActionItemBadge;
20 | import com.mikepenz.actionitembadge.library.ActionItemBadgeAdder;
21 | import com.mikepenz.actionitembadge.library.utils.BadgeStyle;
22 | import com.mikepenz.actionitembadge.library.utils.NumberUtils;
23 | import com.mikepenz.iconics.typeface.library.fontawesome.FontAwesome;
24 | import com.mikepenz.materialdrawer.Drawer;
25 | import com.mikepenz.materialdrawer.DrawerBuilder;
26 | import com.mikepenz.materialdrawer.model.DividerDrawerItem;
27 | import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
28 | import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
29 |
30 |
31 | public class ToolbarActivity extends AppCompatActivity {
32 |
33 | private static final int SAMPLE2_ID = 34536;
34 | private Drawer drawer;
35 | private BadgeStyle style = ActionItemBadge.BadgeStyles.DARK_GREY.getStyle();
36 | private BadgeStyle bigStyle = ActionItemBadge.BadgeStyles.DARK_GREY_LARGE.getStyle();
37 | private int badgeCount = 10;
38 | private int badgeDrawableCount = 100000000;
39 |
40 | @Override
41 | protected void onCreate(Bundle savedInstanceState) {
42 | super.onCreate(savedInstanceState);
43 | setContentView(R.layout.activity_toolbar_main);
44 |
45 |
46 | final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
47 | setSupportActionBar(toolbar);
48 |
49 | drawer = new DrawerBuilder(this)
50 | .withToolbar(toolbar)
51 | .addDrawerItems(
52 | new PrimaryDrawerItem().withName("Activity").withIdentifier(1000).withSelectable(false),
53 | new DividerDrawerItem(),
54 | new PrimaryDrawerItem().withName("Default (Dark Grey)").withIdentifier(1),
55 | new PrimaryDrawerItem().withName("Grey").withIdentifier(2),
56 | new PrimaryDrawerItem().withName("Red").withIdentifier(3),
57 | new PrimaryDrawerItem().withName("Blue").withIdentifier(4),
58 | new PrimaryDrawerItem().withName("Green").withIdentifier(5),
59 | new PrimaryDrawerItem().withName("Purple").withIdentifier(6),
60 | new PrimaryDrawerItem().withName("Yellow").withIdentifier(7),
61 | new PrimaryDrawerItem().withName("Custom").withIdentifier(8),
62 | new DividerDrawerItem(),
63 | new PrimaryDrawerItem().withName("SWITCH").withIdentifier(9).withSelectable(false),
64 | new PrimaryDrawerItem().withName("RESET COUNT").withIdentifier(10).withSelectable(false),
65 | new PrimaryDrawerItem().withName("HIDE BADGE").withIdentifier(11).withSelectable(false)
66 | )
67 | .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
68 | @Override
69 | public boolean onItemClick(View view, int i, IDrawerItem iDrawerItem) {
70 | if (iDrawerItem.getIdentifier() == 1000) {
71 | Intent intent = new Intent(ToolbarActivity.this, MainActivity.class);
72 | startActivity(intent);
73 | return false;
74 | } else if (iDrawerItem.getIdentifier() == 1) {
75 | style = ActionItemBadge.BadgeStyles.DARK_GREY.getStyle();
76 | bigStyle = ActionItemBadge.BadgeStyles.DARK_GREY_LARGE.getStyle();
77 | } else if (iDrawerItem.getIdentifier() == 2) {
78 | style = ActionItemBadge.BadgeStyles.GREY.getStyle();
79 | bigStyle = ActionItemBadge.BadgeStyles.GREY_LARGE.getStyle();
80 | } else if (iDrawerItem.getIdentifier() == 3) {
81 | style = ActionItemBadge.BadgeStyles.RED.getStyle();
82 | bigStyle = ActionItemBadge.BadgeStyles.RED_LARGE.getStyle();
83 | } else if (iDrawerItem.getIdentifier() == 4) {
84 | style = ActionItemBadge.BadgeStyles.BLUE.getStyle();
85 | bigStyle = ActionItemBadge.BadgeStyles.BLUE_LARGE.getStyle();
86 | } else if (iDrawerItem.getIdentifier() == 5) {
87 | style = ActionItemBadge.BadgeStyles.GREEN.getStyle();
88 | bigStyle = ActionItemBadge.BadgeStyles.GREEN_LARGE.getStyle();
89 | } else if (iDrawerItem.getIdentifier() == 6) {
90 | style = ActionItemBadge.BadgeStyles.PURPLE.getStyle();
91 | bigStyle = ActionItemBadge.BadgeStyles.PURPLE_LARGE.getStyle();
92 | } else if (iDrawerItem.getIdentifier() == 7) {
93 | style = ActionItemBadge.BadgeStyles.YELLOW.getStyle();
94 | bigStyle = ActionItemBadge.BadgeStyles.YELLOW_LARGE.getStyle();
95 | } else if (iDrawerItem.getIdentifier() == 8) {
96 | style = new BadgeStyle(BadgeStyle.Style.DEFAULT, R.layout.menu_action_item_badge, Color.parseColor("#FE0665"), Color.parseColor("#CC0548"), Color.parseColor("#EEEEEE"));
97 | bigStyle = new BadgeStyle(BadgeStyle.Style.LARGE, R.layout.menu_action_item_badge_large, Color.parseColor("#FE0665"), Color.parseColor("#CC0548"), Color.parseColor("#EEEEEE"));
98 | } else if (iDrawerItem.getIdentifier() == 9) {
99 | BadgeStyle temp = style;
100 | style = bigStyle;
101 | bigStyle = temp;
102 | Toast.makeText(ToolbarActivity.this, "No icon provided for the previous large style", Toast.LENGTH_LONG).show();
103 | } else if (iDrawerItem.getIdentifier() == 10) {
104 | badgeCount = 10;
105 | } else if (iDrawerItem.getIdentifier() == 11) {
106 | badgeCount = Integer.MIN_VALUE;
107 | }
108 |
109 | invalidateOptionsMenu();
110 |
111 | return false;
112 | }
113 | })
114 | .withFireOnInitialOnClick(true)
115 | .withSelectedItem(3)
116 | .withSavedInstance(savedInstanceState)
117 | .build();
118 |
119 | //init and show about libraries :D
120 | LibsSupportFragment fragment = new LibsBuilder().withFields(R.string.class.getFields()).withVersionShown(true).withLicenseShown(true).supportFragment();
121 | FragmentManager fragmentManager = getSupportFragmentManager();
122 | fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();
123 | }
124 |
125 | @Override
126 | protected void onSaveInstanceState(Bundle outState) {
127 | if (drawer != null) {
128 | outState = drawer.saveInstanceState(outState);
129 | }
130 |
131 | super.onSaveInstanceState(outState);
132 | }
133 |
134 | @Override
135 | public boolean onCreateOptionsMenu(Menu menu) {
136 | // Inflate the menu; this adds items to the action bar if it is present.
137 | getMenuInflater().inflate(R.menu.main, menu);
138 |
139 | if (badgeCount == 0) {
140 | ActionItemBadge.hide(menu.findItem(R.id.item_samplebadge));
141 | } else {
142 | ActionItemBadge.update(this, menu.findItem(R.id.item_samplebadge), FontAwesome.Icon.faw_android, style, badgeCount);
143 | }
144 | if (badgeDrawableCount == 0) {
145 | ActionItemBadge.hide(menu.findItem(R.id.item_sampleBadge_drawable));
146 | } else {
147 | ActionItemBadge.update(this, menu.findItem(R.id.item_sampleBadge_drawable), ContextCompat.getDrawable(this, R.drawable.ic_notification), style, NumberUtils.formatNumber(badgeDrawableCount));
148 | }
149 |
150 | new ActionItemBadgeAdder().act(this).menu(menu).title(R.string.sample_2).itemDetails(0, SAMPLE2_ID, 1).showAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS).add(bigStyle, 1);
151 | return true;
152 | }
153 |
154 | @Override
155 | public boolean onOptionsItemSelected(MenuItem item) {
156 | int id = item.getItemId();
157 | if (id == R.id.item_samplebadge) {
158 | Toast.makeText(this, R.string.sample_3, Toast.LENGTH_SHORT).show();
159 | badgeCount--;
160 | ActionItemBadge.update(item, badgeCount);
161 | } else if (id == R.id.item_sampleBadge_drawable) {
162 | Toast.makeText(this, R.string.sample_3, Toast.LENGTH_SHORT).show();
163 | badgeDrawableCount = badgeDrawableCount - 1000;
164 | ActionItemBadge.update(item, NumberUtils.formatNumber(badgeDrawableCount));
165 | return true;
166 | } else if (id == SAMPLE2_ID) {
167 | Toast.makeText(this, R.string.sample_4, Toast.LENGTH_SHORT).show();
168 | }
169 | return super.onOptionsItemSelected(item);
170 | }
171 | }
172 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_notification.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/app/src/main/res/drawable-hdpi/ic_notification.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_notification.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/app/src/main/res/drawable-mdpi/ic_notification.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_notification.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/app/src/main/res/drawable-xhdpi/ic_notification.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_notification.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/app/src/main/res/drawable-xxhdpi/ic_notification.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/app/src/main/res/drawable-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_notification.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/app/src/main/res/drawable-xxxhdpi/ic_notification.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_toolbar_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
16 |
17 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/aboutlibraries.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | true
4 | true
5 |
7 |
8 | The content is filled with the used libraries section from the AboutLibraries library.
9 |
10 | You can find this library here: https://github.com/mikepenz/Android-ActionItemBadge and the AboutLibraries library here:
11 | https://github.com/mikepenz/AboutLibraries]]>
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | #536dfe
6 | #3f51b5
7 | #DEDEDE
8 | #ff4081
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ActionItemBadge
5 | Open Source
6 |
7 | Sample 1
8 | Sample 2
9 | Sample 3
10 | Sample 4
11 | Sample 5
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
13 |
14 |
15 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext {
3 | release = [
4 | versionName: "4.0.0",
5 | versionCode: 4000
6 | ]
7 |
8 | setup = [
9 | compileSdk: 29,
10 | buildTools: "29.0.2",
11 | minSdk : 14,
12 | targetSdk : 28
13 | ]
14 |
15 | versions = [
16 | androidX : '1.0.0',
17 | recyclerView : '1.1.0-beta05',
18 | appcompat : '1.1.0',
19 | cardview : '1.0.0',
20 | kotlin : '1.3.50',
21 | materialize : '1.2.1',
22 | iconics : '4.0.0',
23 | materialdrawer: '7.0.0-rc08',
24 | aboutlib : '7.0.3',
25 | fastadapter : '4.1.0'
26 | ]
27 | }
28 |
29 | repositories {
30 | google()
31 | jcenter()
32 | maven {
33 | url "https://plugins.gradle.org/m2/"
34 | }
35 | }
36 | dependencies {
37 | classpath 'com.android.tools.build:gradle:3.5.1'
38 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
39 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
40 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
41 | }
42 | }
43 |
44 | allprojects {
45 | group "com.mikepenz"
46 |
47 | repositories {
48 | google()
49 | jcenter()
50 | maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
51 | }
52 | }
--------------------------------------------------------------------------------
/gradle-release.gradle:
--------------------------------------------------------------------------------
1 | @SuppressWarnings(["GroovyUnusedDeclaration", "GrMethodMayBeStatic"])
2 | def isReleaseBuild() {
3 | return !VERSION_NAME.contains("SNAPSHOT")
4 | }
5 |
6 | @SuppressWarnings("GroovyUnusedDeclaration")
7 | def getRepositoryUsername() {
8 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
9 | }
10 |
11 | @SuppressWarnings("GroovyUnusedDeclaration")
12 | def getRepositoryPassword() {
13 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
14 | }
15 |
16 | apply plugin: "com.jfrog.bintray"
17 |
18 | afterEvaluate { project ->
19 | apply plugin: 'maven-publish'
20 | apply plugin: 'com.github.dcendents.android-maven'
21 |
22 | if (JavaVersion.current().isJava8Compatible()) {
23 | allprojects {
24 | tasks.withType(Javadoc) {
25 | options.addStringOption('Xdoclint:none', '-quiet')
26 | }
27 | }
28 | }
29 |
30 | task androidJavadocs(type: Javadoc) {
31 | failOnError = false
32 | source = android.sourceSets.main.java.source
33 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
34 | }
35 |
36 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
37 | classifier = 'javadoc'
38 | from androidJavadocs.destinationDir
39 | }
40 |
41 | task androidSourcesJar(type: Jar) {
42 | classifier = 'sources'
43 | from android.sourceSets.main.java.source
44 | }
45 |
46 | bintray {
47 | dryRun = false
48 | publish = true
49 | override = true
50 | user = project.hasProperty('bintray.user') ? project.property('bintray.user') : System.getenv('BINTRAY_USER')
51 | key = project.hasProperty('bintray.apikey') ? project.property('bintray.apikey') : System.getenv('BINTRAY_API_KEY')
52 | def gpgkey = project.hasProperty('bintray.gpg.key') ? project.property('bintray.gpg.key') : System.getenv('BINTRAY_GPG_KEY')
53 | def gpgpass = project.hasProperty('bintray.gpg.password') ? project.property('bintray.gpg.password') : System.getenv('BINTRAY_GPG_PASS')
54 | def versionName = project.release.versionName
55 |
56 | publications('release')
57 |
58 | pkg {
59 | publish = true
60 |
61 | repo = "maven"
62 | name = GROUP + ":" + POM_ARTIFACT_ID //the name (= identifier) on bintray
63 | desc = POM_DESCRIPTION
64 |
65 | websiteUrl = POM_URL
66 | issueTrackerUrl = POM_SCM_URL_ISSUES
67 | vcsUrl = POM_SCM_URL
68 |
69 | githubRepo = POM_GITHUB_REPO
70 | githubReleaseNotesFile = POM_GITHUB_README
71 |
72 | publicDownloadNumbers = true
73 | licenses = ["Apache-2.0"]
74 | version {
75 | name = versionName
76 | vcsTag = versionName
77 | released = new Date()
78 |
79 | mavenCentralSync {
80 | sync = true
81 | user = getRepositoryUsername()
82 | password = getRepositoryPassword()
83 | close = '1'
84 | }
85 | gpg {
86 | sign = true
87 | passphrase = gpgpass
88 | }
89 | }
90 | }
91 | }
92 |
93 | ext.addDependency = { dependencyNode, group, name, version ->
94 | dependencyNode.appendNode('groupId', group)
95 | dependencyNode.appendNode('artifactId', name)
96 | dependencyNode.appendNode('version', version)
97 | dependencyNode.appendNode('scope', "compile")
98 | }
99 |
100 | def pomConfig = {
101 | licenses {
102 | license {
103 | name POM_LICENCE_NAME
104 | url POM_LICENCE_URL
105 | distribution POM_LICENCE_DIST
106 | }
107 | }
108 | developers {
109 | developer {
110 | id POM_DEVELOPER_ID
111 | name POM_DEVELOPER_NAME
112 | email 'mikepenz@gmail.com'
113 | }
114 | }
115 | scm {
116 | url POM_SCM_URL
117 | connection POM_SCM_CONNECTION
118 | developerConnection POM_SCM_DEV_CONNECTION
119 | }
120 | }
121 |
122 | publishing {
123 | publications {
124 | release(MavenPublication) {
125 | groupId GROUP
126 | artifactId POM_ARTIFACT_ID
127 | version project.release.versionName
128 | artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
129 | artifact androidSourcesJar
130 | artifact androidJavadocsJar
131 |
132 | pom.withXml {
133 | asNode().appendNode('name', POM_NAME)
134 | asNode().appendNode('description', POM_DESCRIPTION)
135 | asNode().appendNode('url', POM_SCM_URL)
136 | def dependenciesNode = asNode().appendNode('dependencies')
137 | configurations.implementation.allDependencies.each {
138 | // Ensure dependencies such as fileTree are not included.
139 | if (it.name != 'unspecified') {
140 | def dependencyNode = dependenciesNode.appendNode('dependency')
141 | if (it.version != "unspecified") {
142 | addDependency(dependencyNode, it.group, it.name, it.version)
143 | } else {
144 | addDependency(dependencyNode, it.getDependencyProject().findProperty("GROUP"), it.getDependencyProject().findProperty("POM_ARTIFACT_ID"), project.release.versionName)
145 | }
146 | }
147 | }
148 | asNode().children().last() + pomConfig
149 | }
150 | }
151 | }
152 | }
153 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Settings specified in this file will override any Gradle settings
4 | # configured through the IDE.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
10 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | GROUP=com.mikepenz
16 |
17 | POM_URL=https://github.com/mikepenz/Android-ActionItemBadge
18 |
19 | POM_SCM_URL=https://github.com/mikepenz/Android-ActionItemBadge
20 | POM_SCM_CONNECTION=scm:git@github.com:mikepenz/Android-ActionItemBadge.git
21 | POM_SCM_DEV_CONNECTION=scm:git@github.com:mikepenz/Android-ActionItemBadge.git
22 | POM_SCM_URL_ISSUES=https://github.com/mikepenz/Android-ActionItemBadge/issues
23 |
24 | POM_GITHUB_REPO=mikepenz/Android-ActionItemBadge
25 | POM_GITHUB_README=README.md
26 |
27 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
28 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
29 | POM_LICENCE_DIST=repo
30 |
31 | POM_DEVELOPER_ID=mikepenz
32 | POM_DEVELOPER_NAME=Mike Penz
33 |
34 | android.useAndroidX=true
35 | android.enableJetifier=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mikepenz/Android-ActionItemBadge/24e5915134f39032c47798b7f2b942d3d32c6418/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Oct 28 18:55:50 CEST 2017
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.2-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 | # 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 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdkVersion setup.compileSdk
6 | buildToolsVersion setup.buildTools
7 |
8 | defaultConfig {
9 | minSdkVersion setup.minSdk
10 | targetSdkVersion setup.targetSdk
11 | versionCode release.versionCode
12 | versionName release.versionName
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 |
23 | dependencies {
24 | // used to provide out of the box icon font support. simplifies development,
25 | // and provides scalable icons. the core is very very light
26 | // https://github.com/mikepenz/Android-Iconics
27 | implementation "com.mikepenz:iconics-core:${versions.iconics}"
28 |
29 | implementation "androidx.appcompat:appcompat:${versions.appcompat}"
30 |
31 | implementation "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}"
32 | }
33 |
34 | apply from: '../gradle-release.gradle'
--------------------------------------------------------------------------------
/library/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_NAME=Android-ActionItemBadge Library
2 | POM_DESCRIPTION=Android-ActionItemBadge Library
3 | POM_ARTIFACT_ID=actionitembadge
4 | POM_PACKAGING=aar
--------------------------------------------------------------------------------
/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 /Entwicklung/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 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/library/src/main/java/com/mikepenz/actionitembadge/library/ActionItemBadge.java:
--------------------------------------------------------------------------------
1 | package com.mikepenz.actionitembadge.library;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Color;
5 | import android.graphics.Point;
6 | import android.graphics.drawable.Drawable;
7 | import android.view.Display;
8 | import android.view.Gravity;
9 | import android.view.MenuItem;
10 | import android.view.View;
11 | import android.view.Window;
12 | import android.widget.FrameLayout;
13 | import android.widget.ImageView;
14 | import android.widget.TextView;
15 | import android.widget.Toast;
16 |
17 | import com.mikepenz.actionitembadge.library.utils.BadgeDrawableBuilder;
18 | import com.mikepenz.actionitembadge.library.utils.BadgeStyle;
19 | import com.mikepenz.actionitembadge.library.utils.UIUtil;
20 | import com.mikepenz.iconics.IconicsColor;
21 | import com.mikepenz.iconics.IconicsDrawable;
22 | import com.mikepenz.iconics.typeface.IIcon;
23 |
24 | /**
25 | * Created by mikepenz on 23.07.14.
26 | */
27 | public class ActionItemBadge {
28 | public enum BadgeStyles {
29 | GREY(new BadgeStyle(BadgeStyle.Style.DEFAULT, R.layout.menu_action_item_badge, Color.parseColor("#e0e0e0"), Color.parseColor("#c7c7c7"), Color.BLACK)),
30 | DARK_GREY(new BadgeStyle(BadgeStyle.Style.DEFAULT, R.layout.menu_action_item_badge, Color.parseColor("#606060"), Color.parseColor("#3e3e3e"), Color.WHITE)),
31 | RED(new BadgeStyle(BadgeStyle.Style.DEFAULT, R.layout.menu_action_item_badge, Color.parseColor("#FF4444"), Color.parseColor("#CC0000"), Color.WHITE)),
32 | BLUE(new BadgeStyle(BadgeStyle.Style.DEFAULT, R.layout.menu_action_item_badge, Color.parseColor("#33B5E5"), Color.parseColor("#0099CC"), Color.WHITE)),
33 | GREEN(new BadgeStyle(BadgeStyle.Style.DEFAULT, R.layout.menu_action_item_badge, Color.parseColor("#99CC00"), Color.parseColor("#669900"), Color.WHITE)),
34 | PURPLE(new BadgeStyle(BadgeStyle.Style.DEFAULT, R.layout.menu_action_item_badge, Color.parseColor("#AA66CC"), Color.parseColor("#9933CC"), Color.WHITE)),
35 | YELLOW(new BadgeStyle(BadgeStyle.Style.DEFAULT, R.layout.menu_action_item_badge, Color.parseColor("#FFBB33"), Color.parseColor("#FF8800"), Color.WHITE)),
36 | GREY_LARGE(new BadgeStyle(BadgeStyle.Style.LARGE, R.layout.menu_action_item_badge_large, Color.parseColor("#e0e0e0"), Color.parseColor("#c7c7c7"), Color.BLACK)),
37 | DARK_GREY_LARGE(new BadgeStyle(BadgeStyle.Style.LARGE, R.layout.menu_action_item_badge_large, Color.parseColor("#606060"), Color.parseColor("#3e3e3e"), Color.WHITE)),
38 | RED_LARGE(new BadgeStyle(BadgeStyle.Style.LARGE, R.layout.menu_action_item_badge_large, Color.parseColor("#FF4444"), Color.parseColor("#CC0000"), Color.WHITE)),
39 | BLUE_LARGE(new BadgeStyle(BadgeStyle.Style.LARGE, R.layout.menu_action_item_badge_large, Color.parseColor("#33B5E5"), Color.parseColor("#0099CC"), Color.WHITE)),
40 | GREEN_LARGE(new BadgeStyle(BadgeStyle.Style.LARGE, R.layout.menu_action_item_badge_large, Color.parseColor("#99CC00"), Color.parseColor("#669900"), Color.WHITE)),
41 | PURPLE_LARGE(new BadgeStyle(BadgeStyle.Style.LARGE, R.layout.menu_action_item_badge_large, Color.parseColor("#AA66CC"), Color.parseColor("#9933CC"), Color.WHITE)),
42 | YELLOW_LARGE(new BadgeStyle(BadgeStyle.Style.LARGE, R.layout.menu_action_item_badge_large, Color.parseColor("#FFBB33"), Color.parseColor("#FF8800"), Color.WHITE)),
43 | ;
44 |
45 | private BadgeStyle style;
46 |
47 | BadgeStyles(BadgeStyle style) {
48 | this.style = style;
49 | }
50 |
51 | public BadgeStyle getStyle() {
52 | return style;
53 | }
54 | }
55 |
56 | public static void update(final Activity act, final MenuItem menu, IIcon icon, int badgeCount) {
57 | if (badgeCount == Integer.MIN_VALUE) {
58 | update(act, menu, new IconicsDrawable(act, icon).color(IconicsColor.colorInt(Color.WHITE)).actionBar(), BadgeStyles.DARK_GREY.getStyle(), null);
59 | } else {
60 | update(act, menu, new IconicsDrawable(act, icon).color(IconicsColor.colorInt(Color.WHITE)).actionBar(), BadgeStyles.DARK_GREY.getStyle(), String.valueOf(badgeCount));
61 | }
62 | }
63 |
64 | public static void update(final Activity act, final MenuItem menu, IIcon icon, String badgeCount) {
65 | update(act, menu, new IconicsDrawable(act, icon).color(IconicsColor.colorInt(Color.WHITE)).actionBar(), BadgeStyles.DARK_GREY.getStyle(), badgeCount);
66 | }
67 |
68 | public static void update(final Activity act, final MenuItem menu, IIcon icon, BadgeStyles style, int badgeCount) {
69 | update(act, menu, icon, style.getStyle(), badgeCount);
70 | }
71 |
72 | public static void update(final Activity act, final MenuItem menu, IIcon icon, BadgeStyle style, int badgeCount) {
73 | if (badgeCount == Integer.MIN_VALUE) {
74 | update(act, menu, new IconicsDrawable(act, icon).color(IconicsColor.colorInt(Color.WHITE)).actionBar(), style, null);
75 | } else {
76 | update(act, menu, new IconicsDrawable(act, icon).color(IconicsColor.colorInt(Color.WHITE)).actionBar(), style, String.valueOf(badgeCount));
77 | }
78 | }
79 |
80 | public static void update(final Activity act, final MenuItem menu, IIcon icon, BadgeStyle style, String badgeCount) {
81 | update(act, menu, new IconicsDrawable(act, icon).color(IconicsColor.colorInt(Color.WHITE)).actionBar(), style, badgeCount);
82 | }
83 |
84 | public static void update(final Activity act, final MenuItem menu, IIcon icon, int iconColor, int badgeCount) {
85 | update(act, menu, icon, iconColor, BadgeStyles.DARK_GREY.getStyle(), badgeCount);
86 | }
87 |
88 | public static void update(final Activity act, final MenuItem menu, IIcon icon, int iconColor, BadgeStyles style, int badgeCount) {
89 | update(act, menu, icon, iconColor, style.getStyle(), badgeCount);
90 | }
91 |
92 | public static void update(final Activity act, final MenuItem menu, IIcon icon, int iconColor, BadgeStyle style, int badgeCount) {
93 | if (badgeCount == Integer.MIN_VALUE) {
94 | update(act, menu, new IconicsDrawable(act, icon).color(IconicsColor.colorInt(iconColor)).actionBar(), style, null);
95 | } else {
96 | update(act, menu, new IconicsDrawable(act, icon).color(IconicsColor.colorInt(iconColor)).actionBar(), style, String.valueOf(badgeCount));
97 | }
98 | }
99 |
100 | public static void update(final Activity act, final MenuItem menu, IIcon icon, int iconColor, BadgeStyle style, String badgeCount) {
101 | update(act, menu, new IconicsDrawable(act, icon).color(IconicsColor.colorInt(iconColor)).actionBar(), style, badgeCount);
102 | }
103 |
104 | public static void update(final Activity act, final MenuItem menu, Drawable icon, BadgeStyles style, int badgeCount) {
105 | if (badgeCount == Integer.MIN_VALUE) {
106 | update(act, menu, icon, style.getStyle(), null);
107 | } else {
108 | update(act, menu, icon, style.getStyle(), String.valueOf(badgeCount));
109 | }
110 | }
111 |
112 | public static void update(final Activity act, final MenuItem menu, Drawable icon, BadgeStyles style, String badgeCount) {
113 | update(act, menu, icon, style.getStyle(), badgeCount);
114 | }
115 |
116 |
117 | public static void update(final MenuItem menu, int badgeCount) {
118 | update(menu, null, badgeCount);
119 | }
120 |
121 | public static void update(final MenuItem menu, String badgeCount) {
122 | update(menu, null, badgeCount);
123 | }
124 |
125 | public static void update(final MenuItem menu, Drawable icon, int badgeCount) {
126 | if (badgeCount == Integer.MIN_VALUE) {
127 | update(null, menu, icon, (BadgeStyle) null, null);
128 | } else {
129 | update(null, menu, icon, (BadgeStyle) null, String.valueOf(badgeCount));
130 | }
131 | }
132 |
133 | public static void update(final MenuItem menu, Drawable icon, String badgeCount) {
134 | update(null, menu, icon, (BadgeStyle) null, badgeCount);
135 |
136 | }
137 |
138 | public static void update(final Activity activity, final MenuItem menu, Drawable icon, BadgeStyle style, int badgeCount) {
139 | update(activity, menu, icon, style, badgeCount, null);
140 | }
141 |
142 | public static void update(final Activity activity, final MenuItem menu, Drawable icon, BadgeStyle style, int badgeCount, ActionItemBadgeListener listener) {
143 | if (badgeCount == Integer.MIN_VALUE) {
144 | update(activity, menu, icon, style, null, listener);
145 | } else {
146 | update(activity, menu, icon, style, String.valueOf(badgeCount), listener);
147 | }
148 | }
149 |
150 | /**
151 | * update the given menu item with icon, badgeCount and style
152 | *
153 | * @param activity use to bind onOptionsItemSelected
154 | * @param menu
155 | * @param icon
156 | * @param style
157 | * @param badgeCount
158 | */
159 | public static void update(final Activity activity, final MenuItem menu, Drawable icon, BadgeStyle style, String badgeCount) {
160 | update(activity, menu, icon, style, badgeCount, null);
161 | }
162 |
163 | /**
164 | * update the given menu item with icon, badgeCount and style
165 | *
166 | * @param activity use to bind onOptionsItemSelected / and to display the toast
167 | * @param menu
168 | * @param icon
169 | * @param style
170 | * @param badgeCount
171 | * @param listener
172 | */
173 | public static void update(final Activity activity, final MenuItem menu, Drawable icon, BadgeStyle style, String badgeCount, final ActionItemBadgeListener listener) {
174 | if (menu == null) return;
175 |
176 | FrameLayout badge;
177 | TextView badgeView;
178 | ImageView imageView;
179 |
180 | if (style == null) {
181 | badge = (FrameLayout) menu.getActionView();
182 | } else {
183 | badge = (FrameLayout) menu.setActionView(style.getLayout()).getActionView();
184 | }
185 |
186 | badgeView = (TextView) badge.findViewById(R.id.menu_badge);
187 | imageView = (ImageView) badge.findViewById(R.id.menu_badge_icon);
188 |
189 | //Display icon in ImageView
190 | if (imageView != null && icon != null) {
191 | imageView.setImageDrawable(icon);
192 | }
193 |
194 | //Bind onOptionsItemSelected to the activity
195 | if (activity != null) {
196 | badge.setOnClickListener(new View.OnClickListener() {
197 | @Override
198 | public void onClick(View v) {
199 | boolean consumed = false;
200 | if (listener != null) {
201 | consumed = listener.onOptionsItemSelected(menu);
202 | }
203 | if (!consumed) {
204 | activity.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, menu);
205 | }
206 | }
207 | });
208 |
209 | badge.setOnLongClickListener(new View.OnLongClickListener() {
210 | @Override
211 | public boolean onLongClick(View v) {
212 | Display display = activity.getWindowManager().getDefaultDisplay();
213 | Point size = new Point();
214 | display.getSize(size);
215 | int width = size.x;
216 | Toast toast = Toast.makeText(activity, menu.getTitle(), Toast.LENGTH_SHORT);
217 | toast.setGravity(Gravity.TOP, width / 5, UIUtil.convertDpToPx(activity, 48)); //your width and height
218 | toast.show();
219 | return true;
220 | }
221 | });
222 | }
223 |
224 | //Apply style if it's set
225 | if (style != null) {
226 | UIUtil.setBackground(badgeView, new BadgeDrawableBuilder().corners(style.getCorner()).color(style.getColor()).colorPressed(style.getColorPressed()).strokeColor(style.getStrokeColor()).stroke(style.getStroke()).build(activity));
227 | badgeView.setTextColor(style.getTextColor());
228 | }
229 |
230 | //Manage min value
231 | if (badgeCount == null) {
232 | badgeView.setVisibility(View.GONE);
233 | } else {
234 | badgeView.setVisibility(View.VISIBLE);
235 | badgeView.setText(badgeCount);
236 | }
237 |
238 | menu.setVisible(true);
239 | }
240 |
241 |
242 | /**
243 | * hide the given menu item
244 | *
245 | * @param menu
246 | */
247 | public static void hide(MenuItem menu) {
248 | menu.setVisible(false);
249 | }
250 |
251 |
252 | public interface ActionItemBadgeListener {
253 | boolean onOptionsItemSelected(MenuItem menu);
254 | }
255 | }
256 |
--------------------------------------------------------------------------------
/library/src/main/java/com/mikepenz/actionitembadge/library/ActionItemBadgeAdder.java:
--------------------------------------------------------------------------------
1 | package com.mikepenz.actionitembadge.library;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Color;
5 | import android.graphics.drawable.Drawable;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 |
9 | import com.mikepenz.actionitembadge.library.utils.BadgeStyle;
10 | import com.mikepenz.iconics.IconicsColor;
11 | import com.mikepenz.iconics.IconicsDrawable;
12 | import com.mikepenz.iconics.typeface.IIcon;
13 |
14 | public class ActionItemBadgeAdder {
15 | public ActionItemBadgeAdder() {
16 |
17 | }
18 |
19 | public ActionItemBadgeAdder(Activity activity, Menu menu, String title) {
20 | this.activity = activity;
21 | this.menu = menu;
22 | this.title = title;
23 | }
24 |
25 | private Activity activity;
26 |
27 | public ActionItemBadgeAdder act(Activity activity) {
28 | this.activity = activity;
29 | return this;
30 | }
31 |
32 | private Menu menu;
33 |
34 | public ActionItemBadgeAdder menu(Menu menu) {
35 | this.menu = menu;
36 | return this;
37 | }
38 |
39 | private String title;
40 |
41 | public ActionItemBadgeAdder title(String title) {
42 | this.title = title;
43 | return this;
44 | }
45 |
46 | public ActionItemBadgeAdder title(int resId) {
47 | if (activity == null) {
48 | throw new RuntimeException("Activity not set");
49 | }
50 |
51 | this.title = activity.getString(resId);
52 | return this;
53 | }
54 |
55 | private Integer groupId;
56 | private Integer itemId;
57 | private Integer order;
58 |
59 | public ActionItemBadgeAdder itemDetails(int groupId, int itemId, int order) {
60 | this.groupId = groupId;
61 | this.itemId = itemId;
62 | this.order = order;
63 | return this;
64 | }
65 |
66 | private Integer showAsAction;
67 |
68 | public ActionItemBadgeAdder showAsAction(int showAsAction) {
69 | this.showAsAction = showAsAction;
70 | return this;
71 | }
72 |
73 | public MenuItem add(int badgeCount) {
74 | return add(ActionItemBadge.BadgeStyles.GREY_LARGE, badgeCount);
75 | }
76 |
77 | public MenuItem add(ActionItemBadge.BadgeStyles style, int badgeCount) {
78 | return add(style.getStyle(), badgeCount);
79 | }
80 |
81 | public MenuItem add(BadgeStyle style, int badgeCount) {
82 | return add((Drawable) null, style, badgeCount, null);
83 | }
84 |
85 | public MenuItem add(IIcon icon, int badgeCount) {
86 | return add(icon, Color.WHITE, badgeCount);
87 | }
88 |
89 | public MenuItem add(IIcon icon, int iconColor, int badgeCount) {
90 | return add(new IconicsDrawable(activity, icon).color(IconicsColor.colorInt(iconColor)).actionBar(), ActionItemBadge.BadgeStyles.GREY, badgeCount);
91 | }
92 |
93 | public MenuItem add(Drawable icon, int badgeCount) {
94 | return add(icon, ActionItemBadge.BadgeStyles.GREY, badgeCount);
95 | }
96 |
97 | public MenuItem add(IIcon icon, ActionItemBadge.BadgeStyles style, int badgeCount) {
98 | return add(icon, style.getStyle(), badgeCount);
99 | }
100 |
101 | public MenuItem add(IIcon icon, BadgeStyle style, int badgeCount) {
102 | return add(icon, Color.WHITE, style, badgeCount);
103 | }
104 |
105 | public MenuItem add(IIcon icon, int iconColor, BadgeStyle style, int badgeCount) {
106 | return add(new IconicsDrawable(activity, icon).color(IconicsColor.colorInt(iconColor)).actionBar(), style, badgeCount, null);
107 | }
108 |
109 | public MenuItem add(Drawable icon, ActionItemBadge.BadgeStyles style, int badgeCount) {
110 | return add(icon, style.getStyle(), badgeCount, null);
111 | }
112 |
113 | public MenuItem add(Drawable icon, BadgeStyle style, int badgeCount, ActionItemBadge.ActionItemBadgeListener listener) {
114 | MenuItem item;
115 | if (groupId != null && itemId != null && order != null) {
116 | item = menu.add(groupId, itemId, order, title);
117 | } else {
118 | item = menu.add(title);
119 | }
120 |
121 | if (showAsAction != null) {
122 | item.setShowAsAction(showAsAction);
123 | }
124 |
125 | item.setActionView(style.getLayout());
126 | ActionItemBadge.update(activity, item, icon, style, badgeCount, listener);
127 | return item;
128 | }
129 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/mikepenz/actionitembadge/library/utils/BadgeDrawableBuilder.java:
--------------------------------------------------------------------------------
1 | package com.mikepenz.actionitembadge.library.utils;
2 |
3 | import android.content.Context;
4 | import android.graphics.drawable.GradientDrawable;
5 | import android.graphics.drawable.StateListDrawable;
6 | import android.util.StateSet;
7 |
8 | import androidx.annotation.ColorInt;
9 | import androidx.core.content.ContextCompat;
10 |
11 | import com.mikepenz.actionitembadge.library.R;
12 |
13 | /**
14 | * Created by mikepenz on 02.07.15.
15 | */
16 | public class BadgeDrawableBuilder {
17 | private int mColor = 0;
18 | private int mColorPressed = 0;
19 | private int mCorners = -1;
20 | private int mStroke = -1;
21 | private int mStrokeColor = 0;
22 |
23 | public BadgeDrawableBuilder() {
24 | }
25 |
26 | public BadgeDrawableBuilder color(@ColorInt int color) {
27 | this.mColor = color;
28 | return this;
29 | }
30 |
31 | public BadgeDrawableBuilder colorPressed(@ColorInt int colorPressed) {
32 | this.mColorPressed = colorPressed;
33 | return this;
34 | }
35 |
36 | public BadgeDrawableBuilder corners(int corners) {
37 | this.mCorners = corners;
38 | return this;
39 | }
40 |
41 | public BadgeDrawableBuilder stroke(int stroke) {
42 | this.mStroke = stroke;
43 | return this;
44 | }
45 |
46 | public BadgeDrawableBuilder strokeColor(@ColorInt int strokeColor) {
47 | this.mStrokeColor = strokeColor;
48 | return this;
49 | }
50 |
51 | public StateListDrawable build(Context ctx) {
52 | StateListDrawable stateListDrawable = new StateListDrawable();
53 |
54 | GradientDrawable normal = (GradientDrawable) ContextCompat.getDrawable(ctx, R.drawable.action_item_badge);
55 | GradientDrawable selected = (GradientDrawable) normal.getConstantState().newDrawable().mutate();
56 |
57 | normal.setColor(mColor);
58 | selected.setColor(mColorPressed);
59 |
60 | if (mStroke > -1) {
61 | normal.setStroke(mStroke, mStrokeColor);
62 | selected.setStroke(mStroke, mStrokeColor);
63 | }
64 |
65 | if (mCorners > -1) {
66 | normal.setCornerRadius(mCorners);
67 | selected.setCornerRadius(mCorners);
68 | }
69 |
70 | stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, selected);
71 | stateListDrawable.addState(StateSet.WILD_CARD, normal);
72 |
73 | return stateListDrawable;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/library/src/main/java/com/mikepenz/actionitembadge/library/utils/BadgeStyle.java:
--------------------------------------------------------------------------------
1 | package com.mikepenz.actionitembadge.library.utils;
2 |
3 | import android.graphics.Color;
4 |
5 | import androidx.annotation.ColorInt;
6 | import androidx.annotation.LayoutRes;
7 |
8 | /**
9 | * Created by mikepenz on 02.07.15.
10 | */
11 | public class BadgeStyle {
12 | public enum Style {
13 | DEFAULT(1),
14 | LARGE(2);
15 |
16 | private int style;
17 |
18 | Style(int style) {
19 | this.style = style;
20 | }
21 |
22 | public int getStyle() {
23 | return style;
24 | }
25 | }
26 |
27 | private Style style;
28 | private int layout;
29 | private int color;
30 | private int colorPressed;
31 | private int textColor = Color.WHITE;
32 | private int corner = -1;
33 | private int stroke = -1;
34 | private int strokeColor = Color.RED;
35 |
36 | public Style getStyle() {
37 | return style;
38 | }
39 |
40 | public BadgeStyle setStyle(Style style) {
41 | this.style = style;
42 | return this;
43 | }
44 |
45 | @LayoutRes
46 | public int getLayout() {
47 | return layout;
48 | }
49 |
50 | public BadgeStyle setLayout(@LayoutRes int layout) {
51 | this.layout = layout;
52 | return this;
53 | }
54 |
55 | @ColorInt
56 | public int getColor() {
57 | return color;
58 | }
59 |
60 | public BadgeStyle setColor(@ColorInt int color) {
61 | this.color = color;
62 | return this;
63 | }
64 |
65 | @ColorInt
66 | public int getColorPressed() {
67 | return colorPressed;
68 | }
69 |
70 | public BadgeStyle setColorPressed(@ColorInt int colorPressed) {
71 | this.colorPressed = colorPressed;
72 | return this;
73 | }
74 |
75 | @ColorInt
76 | public int getTextColor() {
77 | return textColor;
78 | }
79 |
80 | public BadgeStyle setTextColor(@ColorInt int textColor) {
81 | this.textColor = textColor;
82 | return this;
83 | }
84 |
85 | public int getCorner() {
86 | return corner;
87 | }
88 |
89 | public BadgeStyle setCorner(int corner) {
90 | this.corner = corner;
91 | return this;
92 | }
93 |
94 | public int getStroke() {
95 | return stroke;
96 | }
97 |
98 | public BadgeStyle setStroke(int stroke) {
99 | this.stroke = stroke;
100 | return this;
101 | }
102 |
103 | @ColorInt
104 | public int getStrokeColor() {
105 | return strokeColor;
106 | }
107 |
108 | public BadgeStyle setStrokeColor(@ColorInt int strokeColor) {
109 | this.strokeColor = strokeColor;
110 | return this;
111 | }
112 |
113 | public BadgeStyle(Style style, @LayoutRes int layout, @ColorInt int color, @ColorInt int colorPressed) {
114 | this.style = style;
115 | this.layout = layout;
116 | this.color = color;
117 | this.colorPressed = colorPressed;
118 | }
119 |
120 | public BadgeStyle(Style style, @LayoutRes int layout, @ColorInt int color, @ColorInt int colorPressed, @ColorInt int textColor) {
121 | this.style = style;
122 | this.layout = layout;
123 | this.color = color;
124 | this.colorPressed = colorPressed;
125 | this.textColor = textColor;
126 | }
127 |
128 | public BadgeStyle(Style style, @LayoutRes int layout, @ColorInt int color, @ColorInt int colorPressed, @ColorInt int textColor, int corner) {
129 | this.style = style;
130 | this.layout = layout;
131 | this.color = color;
132 | this.colorPressed = colorPressed;
133 | this.textColor = textColor;
134 | this.corner = corner;
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/library/src/main/java/com/mikepenz/actionitembadge/library/utils/NumberUtils.java:
--------------------------------------------------------------------------------
1 | package com.mikepenz.actionitembadge.library.utils;
2 |
3 | import java.util.Map;
4 | import java.util.NavigableMap;
5 | import java.util.TreeMap;
6 |
7 | /**
8 | * Created by prabel on 27.07.15.
9 | */
10 | public class NumberUtils {
11 |
12 | private static final NavigableMap suffixes = new TreeMap<>();
13 |
14 | static {
15 | suffixes.put(1_000L, "k");
16 | suffixes.put(1_000_000L, "M");
17 | suffixes.put(1_000_000_000L, "G");
18 | suffixes.put(1_000_000_000_000L, "T");
19 | suffixes.put(1_000_000_000_000_000L, "P");
20 | suffixes.put(1_000_000_000_000_000_000L, "E");
21 | }
22 |
23 | public static String formatNumber(int value) {
24 | if (value < 0) return "-" + formatNumber(-value);
25 | if (value < 1000) return Long.toString(value);
26 |
27 | final Map.Entry entry = suffixes.floorEntry((long) value);
28 | final Long divideBy = entry.getKey();
29 | final String suffix = entry.getValue();
30 |
31 | final long truncated = value / (divideBy / 10);
32 | final boolean hasDecimal = truncated < 100 && (truncated / 10d) != (truncated / 10);
33 | return hasDecimal ? (truncated / 10d) + suffix : (truncated / 10) + suffix;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/library/src/main/java/com/mikepenz/actionitembadge/library/utils/UIUtil.java:
--------------------------------------------------------------------------------
1 | package com.mikepenz.actionitembadge.library.utils;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.graphics.drawable.Drawable;
6 | import android.view.View;
7 |
8 | import static android.util.TypedValue.COMPLEX_UNIT_DIP;
9 | import static android.util.TypedValue.applyDimension;
10 |
11 | /**
12 | * Created by mikepenz on 02.07.15.
13 | */
14 | public class UIUtil {
15 |
16 | /**
17 | * helper method to set the background depending on the android version
18 | *
19 | * @param v
20 | * @param d
21 | */
22 | @SuppressLint("NewApi")
23 | public static void setBackground(View v, Drawable d) {
24 | if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
25 | v.setBackgroundDrawable(d);
26 | } else {
27 | v.setBackground(d);
28 | }
29 | }
30 |
31 |
32 | public static int convertDpToPx(Context context, float dp) {
33 | return (int) applyDimension(COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/action_item_badge.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/menu_action_item_badge.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
15 |
16 |
28 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/menu_action_item_badge_large.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
24 |
--------------------------------------------------------------------------------
/library/src/main/res/values/aboutlibraries.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | year;owner
4 | Mike Penz
5 | http://mikepenz.com/
6 | Android-ActionItemBadge
7 |
8 | ActionItemBadge is a library which offers a simple and easy to use method to add a badge to your action item!!
10 | ]]>
11 |
12 | 3.3.2
13 | https://github.com/mikepenz/Android-ActionItemBadge
14 | apache_2_0
15 | true
16 | https://github.com/mikepenz/Android-ActionItemBadge
17 |
18 | Mike Penz
19 | 2016
20 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
3 |
4 |
--------------------------------------------------------------------------------