├── .classpath
├── .gitignore
├── .project
├── AndroidManifest.xml
├── LICENSE
├── README.markdown
├── lib
└── android-viewbadger.jar
├── proguard.cfg
├── project.properties
├── res
├── drawable-hdpi
│ ├── badge_ifaux.9.png
│ └── icon.png
├── drawable-ldpi
│ └── icon.png
├── drawable-mdpi
│ └── icon.png
├── layout
│ ├── demos.xml
│ ├── main.xml
│ └── tests.xml
└── values
│ └── strings.xml
└── src
├── com
└── readystatesoftware
│ └── viewbadger
│ └── BadgeView.java
└── viewbadger
└── demo
├── Cheeses.java
└── DemoActivity.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.DS_Store
2 | local.properties
3 | bin/
4 | gen/
5 |
6 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | android-viewbadger
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.markdown:
--------------------------------------------------------------------------------
1 | Android ViewBadger
2 | ==================
3 |
4 | A simple way to "badge" any given Android view at runtime without having to cater for it in layout.
5 |
6 | 
7 | 
8 |
9 | Note: If your aim is to replicate the iOS icon and TabBar badge UI for notifications, consider using Android UI conventions such as the number field of the [Notification](http://developer.android.com/reference/android/app/Notification.html "Notification") class rather than this method.
10 |
11 | Usage
12 | -----
13 |
14 | Simple example:
15 |
16 | View target = findViewById(R.id.target_view);
17 | BadgeView badge = new BadgeView(this, target);
18 | badge.setText("1");
19 | badge.show();
20 |
21 | This project contains a fully working example application. Refer to the `DemoActivity` class for more custom badge examples, including custom backgrounds and animations. `BadgeView` is a subclass of `TextView` so you can use all of `TextView`'s methods to style the appearance of your badge.
22 |
23 | To use ViewBadger in your own Android project, simply copy `android-viewbadger.jar` (available from this repository's package downloads) into your project's `/libs` directory and add it to the build path.
24 |
25 | Current Limitations
26 | -------------------
27 |
28 | - Badging Action Bar items is currently not supported [#2](https://github.com/jgilfelt/android-viewbadger/issues/2)
29 | - Badging views inside RelativeLayout with dependencies may break alignment [#1](https://github.com/jgilfelt/android-viewbadger/issues/1)
30 |
31 | Credits
32 | -------
33 |
34 | Author: Jeff Gilfelt
35 |
36 | The code in this project is licensed under the Apache Software License 2.0.
37 |
38 | Copyright (c) 2011 readyState Software Ltd.
39 |
--------------------------------------------------------------------------------
/lib/android-viewbadger.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jgilfelt/android-viewbadger/e08c3a78cb92c0c8587790b15e73434f972912cf/lib/android-viewbadger.jar
--------------------------------------------------------------------------------
/proguard.cfg:
--------------------------------------------------------------------------------
1 | -optimizationpasses 5
2 | -dontusemixedcaseclassnames
3 | -dontskipnonpubliclibraryclasses
4 | -dontpreverify
5 | -verbose
6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
7 |
8 | -keep public class * extends android.app.Activity
9 | -keep public class * extends android.app.Application
10 | -keep public class * extends android.app.Service
11 | -keep public class * extends android.content.BroadcastReceiver
12 | -keep public class * extends android.content.ContentProvider
13 | -keep public class * extends android.app.backup.BackupAgentHelper
14 | -keep public class * extends android.preference.Preference
15 | -keep public class com.android.vending.licensing.ILicensingService
16 |
17 | -keepclasseswithmembernames class * {
18 | native ;
19 | }
20 |
21 | -keepclasseswithmembers class * {
22 | public (android.content.Context, android.util.AttributeSet);
23 | }
24 |
25 | -keepclasseswithmembers class * {
26 | public (android.content.Context, android.util.AttributeSet, int);
27 | }
28 |
29 | -keepclassmembers class * extends android.app.Activity {
30 | public void *(android.view.View);
31 | }
32 |
33 | -keepclassmembers enum * {
34 | public static **[] values();
35 | public static ** valueOf(java.lang.String);
36 | }
37 |
38 | -keep class * implements android.os.Parcelable {
39 | public static final android.os.Parcelable$Creator *;
40 | }
41 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-4
12 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/badge_ifaux.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jgilfelt/android-viewbadger/e08c3a78cb92c0c8587790b15e73434f972912cf/res/drawable-hdpi/badge_ifaux.9.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jgilfelt/android-viewbadger/e08c3a78cb92c0c8587790b15e73434f972912cf/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/res/drawable-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jgilfelt/android-viewbadger/e08c3a78cb92c0c8587790b15e73434f972912cf/res/drawable-ldpi/icon.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jgilfelt/android-viewbadger/e08c3a78cb92c0c8587790b15e73434f972912cf/res/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/res/layout/demos.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
16 |
17 |
23 |
24 |
30 |
31 |
32 |
33 |
38 |
39 |
44 |
45 |
50 |
51 |
56 |
57 |
62 |
63 |
68 |
69 |
74 |
75 |
80 |
81 |
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
17 |
22 |
27 |
28 |
31 |
32 |
36 |
37 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/res/layout/tests.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
17 |
18 |
24 |
25 |
31 |
32 |
33 |
34 |
39 |
40 |
47 |
48 |
54 |
55 |
56 |
57 |
62 |
63 |
71 |
72 |
79 |
80 |
81 |
82 |
87 |
88 |
94 |
95 |
101 |
102 |
103 |
104 |
108 |
109 |
113 |
114 |
120 |
121 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
140 |
141 |
147 |
148 |
149 |
150 |
156 |
157 |
164 |
165 |
166 |
167 |
173 |
174 |
180 |
181 |
182 |
183 |
186 |
187 |
192 |
193 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | android-viewbadger demo
4 |
5 |
--------------------------------------------------------------------------------
/src/com/readystatesoftware/viewbadger/BadgeView.java:
--------------------------------------------------------------------------------
1 | package com.readystatesoftware.viewbadger;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.graphics.Color;
6 | import android.graphics.Typeface;
7 | import android.graphics.drawable.ShapeDrawable;
8 | import android.graphics.drawable.shapes.RoundRectShape;
9 | import android.util.AttributeSet;
10 | import android.util.TypedValue;
11 | import android.view.Gravity;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.view.ViewGroup.LayoutParams;
15 | import android.view.ViewParent;
16 | import android.view.animation.AccelerateInterpolator;
17 | import android.view.animation.AlphaAnimation;
18 | import android.view.animation.Animation;
19 | import android.view.animation.DecelerateInterpolator;
20 | import android.widget.FrameLayout;
21 | import android.widget.TabWidget;
22 | import android.widget.TextView;
23 |
24 | /**
25 | * A simple text label view that can be applied as a "badge" to any given {@link android.view.View}.
26 | * This class is intended to be instantiated at runtime rather than included in XML layouts.
27 | *
28 | * @author Jeff Gilfelt
29 | */
30 | public class BadgeView extends TextView {
31 |
32 | public static final int POSITION_TOP_LEFT = 1;
33 | public static final int POSITION_TOP_RIGHT = 2;
34 | public static final int POSITION_BOTTOM_LEFT = 3;
35 | public static final int POSITION_BOTTOM_RIGHT = 4;
36 | public static final int POSITION_CENTER = 5;
37 |
38 | private static final int DEFAULT_MARGIN_DIP = 5;
39 | private static final int DEFAULT_LR_PADDING_DIP = 5;
40 | private static final int DEFAULT_CORNER_RADIUS_DIP = 8;
41 | private static final int DEFAULT_POSITION = POSITION_TOP_RIGHT;
42 | private static final int DEFAULT_BADGE_COLOR = Color.parseColor("#CCFF0000"); //Color.RED;
43 | private static final int DEFAULT_TEXT_COLOR = Color.WHITE;
44 |
45 | private static Animation fadeIn;
46 | private static Animation fadeOut;
47 |
48 | private Context context;
49 | private View target;
50 |
51 | private int badgePosition;
52 | private int badgeMarginH;
53 | private int badgeMarginV;
54 | private int badgeColor;
55 |
56 | private boolean isShown;
57 |
58 | private ShapeDrawable badgeBg;
59 |
60 | private int targetTabIndex;
61 |
62 | public BadgeView(Context context) {
63 | this(context, (AttributeSet) null, android.R.attr.textViewStyle);
64 | }
65 |
66 | public BadgeView(Context context, AttributeSet attrs) {
67 | this(context, attrs, android.R.attr.textViewStyle);
68 | }
69 |
70 | /**
71 | * Constructor -
72 | *
73 | * create a new BadgeView instance attached to a target {@link android.view.View}.
74 | *
75 | * @param context context for this view.
76 | * @param target the View to attach the badge to.
77 | */
78 | public BadgeView(Context context, View target) {
79 | this(context, null, android.R.attr.textViewStyle, target, 0);
80 | }
81 |
82 | /**
83 | * Constructor -
84 | *
85 | * create a new BadgeView instance attached to a target {@link android.widget.TabWidget}
86 | * tab at a given index.
87 | *
88 | * @param context context for this view.
89 | * @param target the TabWidget to attach the badge to.
90 | * @param index the position of the tab within the target.
91 | */
92 | public BadgeView(Context context, TabWidget target, int index) {
93 | this(context, null, android.R.attr.textViewStyle, target, index);
94 | }
95 |
96 | public BadgeView(Context context, AttributeSet attrs, int defStyle) {
97 | this(context, attrs, defStyle, null, 0);
98 | }
99 |
100 | public BadgeView(Context context, AttributeSet attrs, int defStyle, View target, int tabIndex) {
101 | super(context, attrs, defStyle);
102 | init(context, target, tabIndex);
103 | }
104 |
105 | private void init(Context context, View target, int tabIndex) {
106 |
107 | this.context = context;
108 | this.target = target;
109 | this.targetTabIndex = tabIndex;
110 |
111 | // apply defaults
112 | badgePosition = DEFAULT_POSITION;
113 | badgeMarginH = dipToPixels(DEFAULT_MARGIN_DIP);
114 | badgeMarginV = badgeMarginH;
115 | badgeColor = DEFAULT_BADGE_COLOR;
116 |
117 | setTypeface(Typeface.DEFAULT_BOLD);
118 | int paddingPixels = dipToPixels(DEFAULT_LR_PADDING_DIP);
119 | setPadding(paddingPixels, 0, paddingPixels, 0);
120 | setTextColor(DEFAULT_TEXT_COLOR);
121 |
122 | fadeIn = new AlphaAnimation(0, 1);
123 | fadeIn.setInterpolator(new DecelerateInterpolator());
124 | fadeIn.setDuration(200);
125 |
126 | fadeOut = new AlphaAnimation(1, 0);
127 | fadeOut.setInterpolator(new AccelerateInterpolator());
128 | fadeOut.setDuration(200);
129 |
130 | isShown = false;
131 |
132 | if (this.target != null) {
133 | applyTo(this.target);
134 | } else {
135 | show();
136 | }
137 |
138 | }
139 |
140 | private void applyTo(View target) {
141 |
142 | LayoutParams lp = target.getLayoutParams();
143 | ViewParent parent = target.getParent();
144 | FrameLayout container = new FrameLayout(context);
145 |
146 | if (target instanceof TabWidget) {
147 |
148 | // set target to the relevant tab child container
149 | target = ((TabWidget) target).getChildTabViewAt(targetTabIndex);
150 | this.target = target;
151 |
152 | ((ViewGroup) target).addView(container,
153 | new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
154 |
155 | this.setVisibility(View.GONE);
156 | container.addView(this);
157 |
158 | } else {
159 |
160 | // TODO verify that parent is indeed a ViewGroup
161 | ViewGroup group = (ViewGroup) parent;
162 | int index = group.indexOfChild(target);
163 |
164 | group.removeView(target);
165 | group.addView(container, index, lp);
166 |
167 | container.addView(target);
168 |
169 | this.setVisibility(View.GONE);
170 | container.addView(this);
171 |
172 | group.invalidate();
173 |
174 | }
175 |
176 | }
177 |
178 | /**
179 | * Make the badge visible in the UI.
180 | *
181 | */
182 | public void show() {
183 | show(false, null);
184 | }
185 |
186 | /**
187 | * Make the badge visible in the UI.
188 | *
189 | * @param animate flag to apply the default fade-in animation.
190 | */
191 | public void show(boolean animate) {
192 | show(animate, fadeIn);
193 | }
194 |
195 | /**
196 | * Make the badge visible in the UI.
197 | *
198 | * @param anim Animation to apply to the view when made visible.
199 | */
200 | public void show(Animation anim) {
201 | show(true, anim);
202 | }
203 |
204 | /**
205 | * Make the badge non-visible in the UI.
206 | *
207 | */
208 | public void hide() {
209 | hide(false, null);
210 | }
211 |
212 | /**
213 | * Make the badge non-visible in the UI.
214 | *
215 | * @param animate flag to apply the default fade-out animation.
216 | */
217 | public void hide(boolean animate) {
218 | hide(animate, fadeOut);
219 | }
220 |
221 | /**
222 | * Make the badge non-visible in the UI.
223 | *
224 | * @param anim Animation to apply to the view when made non-visible.
225 | */
226 | public void hide(Animation anim) {
227 | hide(true, anim);
228 | }
229 |
230 | /**
231 | * Toggle the badge visibility in the UI.
232 | *
233 | */
234 | public void toggle() {
235 | toggle(false, null, null);
236 | }
237 |
238 | /**
239 | * Toggle the badge visibility in the UI.
240 | *
241 | * @param animate flag to apply the default fade-in/out animation.
242 | */
243 | public void toggle(boolean animate) {
244 | toggle(animate, fadeIn, fadeOut);
245 | }
246 |
247 | /**
248 | * Toggle the badge visibility in the UI.
249 | *
250 | * @param animIn Animation to apply to the view when made visible.
251 | * @param animOut Animation to apply to the view when made non-visible.
252 | */
253 | public void toggle(Animation animIn, Animation animOut) {
254 | toggle(true, animIn, animOut);
255 | }
256 |
257 | private void show(boolean animate, Animation anim) {
258 | if (getBackground() == null) {
259 | if (badgeBg == null) {
260 | badgeBg = getDefaultBackground();
261 | }
262 | setBackgroundDrawable(badgeBg);
263 | }
264 | applyLayoutParams();
265 |
266 | if (animate) {
267 | this.startAnimation(anim);
268 | }
269 | this.setVisibility(View.VISIBLE);
270 | isShown = true;
271 | }
272 |
273 | private void hide(boolean animate, Animation anim) {
274 | this.setVisibility(View.GONE);
275 | if (animate) {
276 | this.startAnimation(anim);
277 | }
278 | isShown = false;
279 | }
280 |
281 | private void toggle(boolean animate, Animation animIn, Animation animOut) {
282 | if (isShown) {
283 | hide(animate && (animOut != null), animOut);
284 | } else {
285 | show(animate && (animIn != null), animIn);
286 | }
287 | }
288 |
289 | /**
290 | * Increment the numeric badge label. If the current badge label cannot be converted to
291 | * an integer value, its label will be set to "0".
292 | *
293 | * @param offset the increment offset.
294 | */
295 | public int increment(int offset) {
296 | CharSequence txt = getText();
297 | int i;
298 | if (txt != null) {
299 | try {
300 | i = Integer.parseInt(txt.toString());
301 | } catch (NumberFormatException e) {
302 | i = 0;
303 | }
304 | } else {
305 | i = 0;
306 | }
307 | i = i + offset;
308 | setText(String.valueOf(i));
309 | return i;
310 | }
311 |
312 | /**
313 | * Decrement the numeric badge label. If the current badge label cannot be converted to
314 | * an integer value, its label will be set to "0".
315 | *
316 | * @param offset the decrement offset.
317 | */
318 | public int decrement(int offset) {
319 | return increment(-offset);
320 | }
321 |
322 | private ShapeDrawable getDefaultBackground() {
323 |
324 | int r = dipToPixels(DEFAULT_CORNER_RADIUS_DIP);
325 | float[] outerR = new float[] {r, r, r, r, r, r, r, r};
326 |
327 | RoundRectShape rr = new RoundRectShape(outerR, null, null);
328 | ShapeDrawable drawable = new ShapeDrawable(rr);
329 | drawable.getPaint().setColor(badgeColor);
330 |
331 | return drawable;
332 |
333 | }
334 |
335 | private void applyLayoutParams() {
336 |
337 | FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
338 |
339 | switch (badgePosition) {
340 | case POSITION_TOP_LEFT:
341 | lp.gravity = Gravity.LEFT | Gravity.TOP;
342 | lp.setMargins(badgeMarginH, badgeMarginV, 0, 0);
343 | break;
344 | case POSITION_TOP_RIGHT:
345 | lp.gravity = Gravity.RIGHT | Gravity.TOP;
346 | lp.setMargins(0, badgeMarginV, badgeMarginH, 0);
347 | break;
348 | case POSITION_BOTTOM_LEFT:
349 | lp.gravity = Gravity.LEFT | Gravity.BOTTOM;
350 | lp.setMargins(badgeMarginH, 0, 0, badgeMarginV);
351 | break;
352 | case POSITION_BOTTOM_RIGHT:
353 | lp.gravity = Gravity.RIGHT | Gravity.BOTTOM;
354 | lp.setMargins(0, 0, badgeMarginH, badgeMarginV);
355 | break;
356 | case POSITION_CENTER:
357 | lp.gravity = Gravity.CENTER;
358 | lp.setMargins(0, 0, 0, 0);
359 | break;
360 | default:
361 | break;
362 | }
363 |
364 | setLayoutParams(lp);
365 |
366 | }
367 |
368 | /**
369 | * Returns the target View this badge has been attached to.
370 | *
371 | */
372 | public View getTarget() {
373 | return target;
374 | }
375 |
376 | /**
377 | * Is this badge currently visible in the UI?
378 | *
379 | */
380 | @Override
381 | public boolean isShown() {
382 | return isShown;
383 | }
384 |
385 | /**
386 | * Returns the positioning of this badge.
387 | *
388 | * one of POSITION_TOP_LEFT, POSITION_TOP_RIGHT, POSITION_BOTTOM_LEFT, POSITION_BOTTOM_RIGHT, POSTION_CENTER.
389 | *
390 | */
391 | public int getBadgePosition() {
392 | return badgePosition;
393 | }
394 |
395 | /**
396 | * Set the positioning of this badge.
397 | *
398 | * @param layoutPosition one of POSITION_TOP_LEFT, POSITION_TOP_RIGHT, POSITION_BOTTOM_LEFT, POSITION_BOTTOM_RIGHT, POSTION_CENTER.
399 | *
400 | */
401 | public void setBadgePosition(int layoutPosition) {
402 | this.badgePosition = layoutPosition;
403 | }
404 |
405 | /**
406 | * Returns the horizontal margin from the target View that is applied to this badge.
407 | *
408 | */
409 | public int getHorizontalBadgeMargin() {
410 | return badgeMarginH;
411 | }
412 |
413 | /**
414 | * Returns the vertical margin from the target View that is applied to this badge.
415 | *
416 | */
417 | public int getVerticalBadgeMargin() {
418 | return badgeMarginV;
419 | }
420 |
421 | /**
422 | * Set the horizontal/vertical margin from the target View that is applied to this badge.
423 | *
424 | * @param badgeMargin the margin in pixels.
425 | */
426 | public void setBadgeMargin(int badgeMargin) {
427 | this.badgeMarginH = badgeMargin;
428 | this.badgeMarginV = badgeMargin;
429 | }
430 |
431 | /**
432 | * Set the horizontal/vertical margin from the target View that is applied to this badge.
433 | *
434 | * @param horizontal margin in pixels.
435 | * @param vertical margin in pixels.
436 | */
437 | public void setBadgeMargin(int horizontal, int vertical) {
438 | this.badgeMarginH = horizontal;
439 | this.badgeMarginV = vertical;
440 | }
441 |
442 | /**
443 | * Returns the color value of the badge background.
444 | *
445 | */
446 | public int getBadgeBackgroundColor() {
447 | return badgeColor;
448 | }
449 |
450 | /**
451 | * Set the color value of the badge background.
452 | *
453 | * @param badgeColor the badge background color.
454 | */
455 | public void setBadgeBackgroundColor(int badgeColor) {
456 | this.badgeColor = badgeColor;
457 | badgeBg = getDefaultBackground();
458 | }
459 |
460 | private int dipToPixels(int dip) {
461 | Resources r = getResources();
462 | float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, r.getDisplayMetrics());
463 | return (int) px;
464 | }
465 |
466 | }
467 |
--------------------------------------------------------------------------------
/src/viewbadger/demo/Cheeses.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package viewbadger.demo;
18 |
19 |
20 | public class Cheeses {
21 |
22 | public static final String[] sCheeseStrings = {
23 | "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi",
24 | "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale",
25 | "Aisy Cendre", "Allgauer Emmentaler", "Alverca", "Ambert", "American Cheese",
26 | "Ami du Chambertin", "Anejo Enchilado", "Anneau du Vic-Bilh", "Anthoriro", "Appenzell",
27 | "Aragon", "Ardi Gasna", "Ardrahan", "Armenian String", "Aromes au Gene de Marc",
28 | "Asadero", "Asiago", "Aubisque Pyrenees", "Autun", "Avaxtskyr", "Baby Swiss",
29 | "Babybel", "Baguette Laonnaise", "Bakers", "Baladi", "Balaton", "Bandal", "Banon",
30 | "Barry's Bay Cheddar", "Basing", "Basket Cheese", "Bath Cheese", "Bavarian Bergkase",
31 | "Baylough", "Beaufort", "Beauvoorde", "Beenleigh Blue", "Beer Cheese", "Bel Paese",
32 | "Bergader", "Bergere Bleue", "Berkswell", "Beyaz Peynir", "Bierkase", "Bishop Kennedy",
33 | "Blarney", "Bleu d'Auvergne", "Bleu de Gex", "Bleu de Laqueuille",
34 | "Bleu de Septmoncel", "Bleu Des Causses", "Blue", "Blue Castello", "Blue Rathgore",
35 | "Blue Vein (Australian)", "Blue Vein Cheeses", "Bocconcini", "Bocconcini (Australian)",
36 | "Boeren Leidenkaas", "Bonchester", "Bosworth", "Bougon", "Boule Du Roves",
37 | "Boulette d'Avesnes", "Boursault", "Boursin", "Bouyssou", "Bra", "Braudostur",
38 | "Breakfast Cheese", "Brebis du Lavort", "Brebis du Lochois", "Brebis du Puyfaucon",
39 | "Bresse Bleu", "Brick", "Brie", "Brie de Meaux", "Brie de Melun", "Brillat-Savarin",
40 | "Brin", "Brin d' Amour", "Brin d'Amour", "Brinza (Burduf Brinza)",
41 | "Briquette de Brebis", "Briquette du Forez", "Broccio", "Broccio Demi-Affine",
42 | "Brousse du Rove", "Bruder Basil", "Brusselae Kaas (Fromage de Bruxelles)", "Bryndza",
43 | "Buchette d'Anjou", "Buffalo", "Burgos", "Butte", "Butterkase", "Button (Innes)",
44 | "Buxton Blue", "Cabecou", "Caboc", "Cabrales", "Cachaille", "Caciocavallo", "Caciotta",
45 | "Caerphilly", "Cairnsmore", "Calenzana", "Cambazola", "Camembert de Normandie",
46 | "Canadian Cheddar", "Canestrato", "Cantal", "Caprice des Dieux", "Capricorn Goat",
47 | "Capriole Banon", "Carre de l'Est", "Casciotta di Urbino", "Cashel Blue", "Castellano",
48 | "Castelleno", "Castelmagno", "Castelo Branco", "Castigliano", "Cathelain",
49 | "Celtic Promise", "Cendre d'Olivet", "Cerney", "Chabichou", "Chabichou du Poitou",
50 | "Chabis de Gatine", "Chaource", "Charolais", "Chaumes", "Cheddar",
51 | "Cheddar Clothbound", "Cheshire", "Chevres", "Chevrotin des Aravis", "Chontaleno",
52 | "Civray", "Coeur de Camembert au Calvados", "Coeur de Chevre", "Colby", "Cold Pack",
53 | "Comte", "Coolea", "Cooleney", "Coquetdale", "Corleggy", "Cornish Pepper",
54 | "Cotherstone", "Cotija", "Cottage Cheese", "Cottage Cheese (Australian)",
55 | "Cougar Gold", "Coulommiers", "Coverdale", "Crayeux de Roncq", "Cream Cheese",
56 | "Cream Havarti", "Crema Agria", "Crema Mexicana", "Creme Fraiche", "Crescenza",
57 | "Croghan", "Crottin de Chavignol", "Crottin du Chavignol", "Crowdie", "Crowley",
58 | "Cuajada", "Curd", "Cure Nantais", "Curworthy", "Cwmtawe Pecorino",
59 | "Cypress Grove Chevre", "Danablu (Danish Blue)", "Danbo", "Danish Fontina",
60 | "Daralagjazsky", "Dauphin", "Delice des Fiouves", "Denhany Dorset Drum", "Derby",
61 | "Dessertnyj Belyj", "Devon Blue", "Devon Garland", "Dolcelatte", "Doolin",
62 | "Doppelrhamstufel", "Dorset Blue Vinney", "Double Gloucester", "Double Worcester",
63 | "Dreux a la Feuille", "Dry Jack", "Duddleswell", "Dunbarra", "Dunlop", "Dunsyre Blue",
64 | "Duroblando", "Durrus", "Dutch Mimolette (Commissiekaas)", "Edam", "Edelpilz",
65 | "Emental Grand Cru", "Emlett", "Emmental", "Epoisses de Bourgogne", "Esbareich",
66 | "Esrom", "Etorki", "Evansdale Farmhouse Brie", "Evora De L'Alentejo", "Exmoor Blue",
67 | "Explorateur", "Feta", "Feta (Australian)", "Figue", "Filetta", "Fin-de-Siecle",
68 | "Finlandia Swiss", "Finn", "Fiore Sardo", "Fleur du Maquis", "Flor de Guia",
69 | "Flower Marie", "Folded", "Folded cheese with mint", "Fondant de Brebis",
70 | "Fontainebleau", "Fontal", "Fontina Val d'Aosta", "Formaggio di capra", "Fougerus",
71 | "Four Herb Gouda", "Fourme d' Ambert", "Fourme de Haute Loire", "Fourme de Montbrison",
72 | "Fresh Jack", "Fresh Mozzarella", "Fresh Ricotta", "Fresh Truffles", "Fribourgeois",
73 | "Friesekaas", "Friesian", "Friesla", "Frinault", "Fromage a Raclette", "Fromage Corse",
74 | "Fromage de Montagne de Savoie", "Fromage Frais", "Fruit Cream Cheese",
75 | "Frying Cheese", "Fynbo", "Gabriel", "Galette du Paludier", "Galette Lyonnaise",
76 | "Galloway Goat's Milk Gems", "Gammelost", "Gaperon a l'Ail", "Garrotxa", "Gastanberra",
77 | "Geitost", "Gippsland Blue", "Gjetost", "Gloucester", "Golden Cross", "Gorgonzola",
78 | "Gornyaltajski", "Gospel Green", "Gouda", "Goutu", "Gowrie", "Grabetto", "Graddost",
79 | "Grafton Village Cheddar", "Grana", "Grana Padano", "Grand Vatel",
80 | "Grataron d' Areches", "Gratte-Paille", "Graviera", "Greuilh", "Greve",
81 | "Gris de Lille", "Gruyere", "Gubbeen", "Guerbigny", "Halloumi",
82 | "Halloumy (Australian)", "Haloumi-Style Cheese", "Harbourne Blue", "Havarti",
83 | "Heidi Gruyere", "Hereford Hop", "Herrgardsost", "Herriot Farmhouse", "Herve",
84 | "Hipi Iti", "Hubbardston Blue Cow", "Hushallsost", "Iberico", "Idaho Goatster",
85 | "Idiazabal", "Il Boschetto al Tartufo", "Ile d'Yeu", "Isle of Mull", "Jarlsberg",
86 | "Jermi Tortes", "Jibneh Arabieh", "Jindi Brie", "Jubilee Blue", "Juustoleipa",
87 | "Kadchgall", "Kaseri", "Kashta", "Kefalotyri", "Kenafa", "Kernhem", "Kervella Affine",
88 | "Kikorangi", "King Island Cape Wickham Brie", "King River Gold", "Klosterkaese",
89 | "Knockalara", "Kugelkase", "L'Aveyronnais", "L'Ecir de l'Aubrac", "La Taupiniere",
90 | "La Vache Qui Rit", "Laguiole", "Lairobell", "Lajta", "Lanark Blue", "Lancashire",
91 | "Langres", "Lappi", "Laruns", "Lavistown", "Le Brin", "Le Fium Orbo", "Le Lacandou",
92 | "Le Roule", "Leafield", "Lebbene", "Leerdammer", "Leicester", "Leyden", "Limburger",
93 | "Lincolnshire Poacher", "Lingot Saint Bousquet d'Orb", "Liptauer", "Little Rydings",
94 | "Livarot", "Llanboidy", "Llanglofan Farmhouse", "Loch Arthur Farmhouse",
95 | "Loddiswell Avondale", "Longhorn", "Lou Palou", "Lou Pevre", "Lyonnais", "Maasdam",
96 | "Macconais", "Mahoe Aged Gouda", "Mahon", "Malvern", "Mamirolle", "Manchego",
97 | "Manouri", "Manur", "Marble Cheddar", "Marbled Cheeses", "Maredsous", "Margotin",
98 | "Maribo", "Maroilles", "Mascares", "Mascarpone", "Mascarpone (Australian)",
99 | "Mascarpone Torta", "Matocq", "Maytag Blue", "Meira", "Menallack Farmhouse",
100 | "Menonita", "Meredith Blue", "Mesost", "Metton (Cancoillotte)", "Meyer Vintage Gouda",
101 | "Mihalic Peynir", "Milleens", "Mimolette", "Mine-Gabhar", "Mini Baby Bells", "Mixte",
102 | "Molbo", "Monastery Cheeses", "Mondseer", "Mont D'or Lyonnais", "Montasio",
103 | "Monterey Jack", "Monterey Jack Dry", "Morbier", "Morbier Cru de Montagne",
104 | "Mothais a la Feuille", "Mozzarella", "Mozzarella (Australian)",
105 | "Mozzarella di Bufala", "Mozzarella Fresh, in water", "Mozzarella Rolls", "Munster",
106 | "Murol", "Mycella", "Myzithra", "Naboulsi", "Nantais", "Neufchatel",
107 | "Neufchatel (Australian)", "Niolo", "Nokkelost", "Northumberland", "Oaxaca",
108 | "Olde York", "Olivet au Foin", "Olivet Bleu", "Olivet Cendre",
109 | "Orkney Extra Mature Cheddar", "Orla", "Oschtjepka", "Ossau Fermier", "Ossau-Iraty",
110 | "Oszczypek", "Oxford Blue", "P'tit Berrichon", "Palet de Babligny", "Paneer", "Panela",
111 | "Pannerone", "Pant ys Gawn", "Parmesan (Parmigiano)", "Parmigiano Reggiano",
112 | "Pas de l'Escalette", "Passendale", "Pasteurized Processed", "Pate de Fromage",
113 | "Patefine Fort", "Pave d'Affinois", "Pave d'Auge", "Pave de Chirac", "Pave du Berry",
114 | "Pecorino", "Pecorino in Walnut Leaves", "Pecorino Romano", "Peekskill Pyramid",
115 | "Pelardon des Cevennes", "Pelardon des Corbieres", "Penamellera", "Penbryn",
116 | "Pencarreg", "Perail de Brebis", "Petit Morin", "Petit Pardou", "Petit-Suisse",
117 | "Picodon de Chevre", "Picos de Europa", "Piora", "Pithtviers au Foin",
118 | "Plateau de Herve", "Plymouth Cheese", "Podhalanski", "Poivre d'Ane", "Polkolbin",
119 | "Pont l'Eveque", "Port Nicholson", "Port-Salut", "Postel", "Pouligny-Saint-Pierre",
120 | "Pourly", "Prastost", "Pressato", "Prince-Jean", "Processed Cheddar", "Provolone",
121 | "Provolone (Australian)", "Pyengana Cheddar", "Pyramide", "Quark",
122 | "Quark (Australian)", "Quartirolo Lombardo", "Quatre-Vents", "Quercy Petit",
123 | "Queso Blanco", "Queso Blanco con Frutas --Pina y Mango", "Queso de Murcia",
124 | "Queso del Montsec", "Queso del Tietar", "Queso Fresco", "Queso Fresco (Adobera)",
125 | "Queso Iberico", "Queso Jalapeno", "Queso Majorero", "Queso Media Luna",
126 | "Queso Para Frier", "Queso Quesadilla", "Rabacal", "Raclette", "Ragusano", "Raschera",
127 | "Reblochon", "Red Leicester", "Regal de la Dombes", "Reggianito", "Remedou",
128 | "Requeson", "Richelieu", "Ricotta", "Ricotta (Australian)", "Ricotta Salata", "Ridder",
129 | "Rigotte", "Rocamadour", "Rollot", "Romano", "Romans Part Dieu", "Roncal", "Roquefort",
130 | "Roule", "Rouleau De Beaulieu", "Royalp Tilsit", "Rubens", "Rustinu", "Saaland Pfarr",
131 | "Saanenkaese", "Saga", "Sage Derby", "Sainte Maure", "Saint-Marcellin",
132 | "Saint-Nectaire", "Saint-Paulin", "Salers", "Samso", "San Simon", "Sancerre",
133 | "Sap Sago", "Sardo", "Sardo Egyptian", "Sbrinz", "Scamorza", "Schabzieger", "Schloss",
134 | "Selles sur Cher", "Selva", "Serat", "Seriously Strong Cheddar", "Serra da Estrela",
135 | "Sharpam", "Shelburne Cheddar", "Shropshire Blue", "Siraz", "Sirene", "Smoked Gouda",
136 | "Somerset Brie", "Sonoma Jack", "Sottocenare al Tartufo", "Soumaintrain",
137 | "Sourire Lozerien", "Spenwood", "Sraffordshire Organic", "St. Agur Blue Cheese",
138 | "Stilton", "Stinking Bishop", "String", "Sussex Slipcote", "Sveciaost", "Swaledale",
139 | "Sweet Style Swiss", "Swiss", "Syrian (Armenian String)", "Tala", "Taleggio", "Tamie",
140 | "Tasmania Highland Chevre Log", "Taupiniere", "Teifi", "Telemea", "Testouri",
141 | "Tete de Moine", "Tetilla", "Texas Goat Cheese", "Tibet", "Tillamook Cheddar",
142 | "Tilsit", "Timboon Brie", "Toma", "Tomme Brulee", "Tomme d'Abondance",
143 | "Tomme de Chevre", "Tomme de Romans", "Tomme de Savoie", "Tomme des Chouans", "Tommes",
144 | "Torta del Casar", "Toscanello", "Touree de L'Aubier", "Tourmalet",
145 | "Trappe (Veritable)", "Trois Cornes De Vendee", "Tronchon", "Trou du Cru", "Truffe",
146 | "Tupi", "Turunmaa", "Tymsboro", "Tyn Grug", "Tyning", "Ubriaco", "Ulloa",
147 | "Vacherin-Fribourgeois", "Valencay", "Vasterbottenost", "Venaco", "Vendomois",
148 | "Vieux Corse", "Vignotte", "Vulscombe", "Waimata Farmhouse Blue",
149 | "Washed Rind Cheese (Australian)", "Waterloo", "Weichkaese", "Wellington",
150 | "Wensleydale", "White Stilton", "Whitestone Farmhouse", "Wigmore", "Woodside Cabecou",
151 | "Xanadu", "Xynotyro", "Yarg Cornish", "Yarra Valley Pyramid", "Yorkshire Blue",
152 | "Zamorano", "Zanetti Grana Padano", "Zanetti Parmigiano Reggiano"
153 | };
154 |
155 | }
156 |
--------------------------------------------------------------------------------
/src/viewbadger/demo/DemoActivity.java:
--------------------------------------------------------------------------------
1 | package viewbadger.demo;
2 |
3 | import android.app.TabActivity;
4 | import android.content.Context;
5 | import android.graphics.Color;
6 | import android.os.Bundle;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.View.OnClickListener;
10 | import android.view.ViewGroup;
11 | import android.view.animation.BounceInterpolator;
12 | import android.view.animation.TranslateAnimation;
13 | import android.widget.BaseAdapter;
14 | import android.widget.Button;
15 | import android.widget.ListView;
16 | import android.widget.TabHost;
17 | import android.widget.TabWidget;
18 | import android.widget.TextView;
19 | import android.widget.Toast;
20 |
21 | import com.readystatesoftware.viewbadger.BadgeView;
22 | import com.readystatesoftware.viewbadger.R;
23 |
24 | public class DemoActivity extends TabActivity {
25 |
26 | private static final String[] DATA = Cheeses.sCheeseStrings;
27 |
28 | Button btnPosition;
29 | Button btnColour;
30 | Button btnAnim1;
31 | Button btnAnim2;
32 | Button btnCustom;
33 | Button btnClick;
34 | Button btnTab;
35 | Button btnIncrement;
36 |
37 | ListView listDemo;
38 |
39 | BadgeView badge1;
40 | BadgeView badge2;
41 | BadgeView badge3;
42 | BadgeView badge4;
43 | BadgeView badge5;
44 | BadgeView badge6;
45 | BadgeView badge7;
46 | BadgeView badge8;
47 |
48 | @Override
49 | public void onCreate(Bundle savedInstanceState) {
50 | super.onCreate(savedInstanceState);
51 | setContentView(R.layout.main);
52 |
53 | final TabHost tabHost = getTabHost();
54 |
55 | tabHost.addTab(tabHost.newTabSpec("demos")
56 | .setIndicator("Badge Demos")
57 | .setContent(R.id.tab1));
58 |
59 | tabHost.addTab(tabHost.newTabSpec("adapter")
60 | .setIndicator("List Adapter")
61 | .setContent(R.id.tab2));
62 |
63 | tabHost.addTab(tabHost.newTabSpec("tests")
64 | .setIndicator("Layout Tests")
65 | .setContent(R.id.tab3));
66 |
67 | // *** default badge ***
68 |
69 | View target = findViewById(R.id.default_target);
70 | BadgeView badge = new BadgeView(this, target);
71 | badge.setText("1");
72 | badge.show();
73 |
74 | // *** set position ***
75 |
76 | btnPosition = (Button) findViewById(R.id.position_target);
77 | badge1 = new BadgeView(this, btnPosition);
78 | badge1.setText("12");
79 | badge1.setBadgePosition(BadgeView.POSITION_CENTER);
80 | btnPosition.setOnClickListener(new OnClickListener() {
81 | @Override
82 | public void onClick(View v) {
83 | badge1.toggle();
84 | }
85 | });
86 |
87 | // *** badge/text size & colour ***
88 |
89 | btnColour = (Button) findViewById(R.id.colour_target);
90 | badge2 = new BadgeView(this, btnColour);
91 | badge2.setText("New!");
92 | badge2.setTextColor(Color.BLUE);
93 | badge2.setBadgeBackgroundColor(Color.YELLOW);
94 | badge2.setTextSize(12);
95 | btnColour.setOnClickListener(new OnClickListener() {
96 | @Override
97 | public void onClick(View v) {
98 | badge2.toggle();
99 | }
100 | });
101 |
102 | // *** default animation ***
103 |
104 | btnAnim1 = (Button) findViewById(R.id.anim1_target);
105 | badge3 = new BadgeView(this, btnAnim1);
106 | badge3.setText("84");
107 | btnAnim1.setOnClickListener(new OnClickListener() {
108 | @Override
109 | public void onClick(View v) {
110 | badge3.toggle(true);
111 | }
112 | });
113 |
114 | // *** custom animation ***
115 |
116 | btnAnim2 = (Button) findViewById(R.id.anim2_target);
117 | badge4 = new BadgeView(this, btnAnim2);
118 | badge4.setText("123");
119 | badge4.setBadgePosition(BadgeView.POSITION_TOP_LEFT);
120 | badge4.setBadgeMargin(15, 10);
121 | badge4.setBadgeBackgroundColor(Color.parseColor("#A4C639"));
122 | btnAnim2.setOnClickListener(new OnClickListener() {
123 | @Override
124 | public void onClick(View v) {
125 | TranslateAnimation anim = new TranslateAnimation(-100, 0, 0, 0);
126 | anim.setInterpolator(new BounceInterpolator());
127 | anim.setDuration(1000);
128 | badge4.toggle(anim, null);
129 | }
130 | });
131 |
132 | // *** custom background ***
133 |
134 | btnCustom = (Button) findViewById(R.id.custom_target);
135 | badge5 = new BadgeView(this, btnCustom);
136 | badge5.setText("37");
137 | badge5.setBackgroundResource(R.drawable.badge_ifaux);
138 | badge5.setTextSize(16);
139 | btnCustom.setOnClickListener(new OnClickListener() {
140 | @Override
141 | public void onClick(View v) {
142 | badge5.toggle(true);
143 | }
144 | });
145 |
146 | // *** clickable badge ***
147 |
148 | btnClick = (Button) findViewById(R.id.click_target);
149 | badge6 = new BadgeView(this, btnClick);
150 | badge6.setText("click me");
151 | badge6.setBadgeBackgroundColor(Color.BLUE);
152 | badge6.setTextSize(16);
153 | badge6.setOnClickListener(new OnClickListener() {
154 | @Override
155 | public void onClick(View v) {
156 | Toast.makeText(DemoActivity.this, "clicked badge", Toast.LENGTH_SHORT).show();
157 | }
158 | });
159 | btnClick.setOnClickListener(new OnClickListener() {
160 | @Override
161 | public void onClick(View v) {
162 | badge6.toggle();
163 | }
164 | });
165 |
166 | // *** tab ***
167 |
168 | TabWidget tabs = (TabWidget) findViewById(android.R.id.tabs);
169 |
170 | btnTab = (Button) findViewById(R.id.tab_btn);
171 | badge7 = new BadgeView(this, tabs, 0);
172 | badge7.setText("5");
173 | btnTab.setOnClickListener(new OnClickListener() {
174 | @Override
175 | public void onClick(View v) {
176 | badge7.toggle();
177 | }
178 | });
179 |
180 | // *** increment ***
181 |
182 | btnIncrement = (Button) findViewById(R.id.increment_target);
183 | badge8 = new BadgeView(this, btnIncrement);
184 | badge8.setText("0");
185 | btnIncrement.setOnClickListener(new OnClickListener() {
186 | @Override
187 | public void onClick(View v) {
188 | if (badge8.isShown()) {
189 | badge8.increment(1);
190 | } else {
191 | badge8.show();
192 | }
193 | }
194 | });
195 |
196 | // *** list adapter ****
197 |
198 | listDemo = (ListView) findViewById(R.id.tab2);
199 | listDemo.setAdapter(new BadgeAdapter(this));
200 |
201 | }
202 |
203 | @Override
204 | protected void onResume() {
205 | super.onResume();
206 |
207 | BadgeView badge;
208 | View target;
209 |
210 | // *** test linear layout container ***
211 |
212 | target = findViewById(R.id.linear_target);
213 | badge = new BadgeView(this, target);
214 | badge.setText("OK");
215 | badge.show();
216 |
217 | // *** test relative layout container ***
218 |
219 | target = findViewById(R.id.relative_target);
220 | badge = new BadgeView(this, target);
221 | badge.setText("OK");
222 | badge.show();
223 |
224 | // *** test frame layout container ***
225 |
226 | target = findViewById(R.id.frame_target);
227 | badge = new BadgeView(this, target);
228 | badge.setText("OK");
229 | badge.show();
230 |
231 | // *** test table layout container ***
232 |
233 | target = findViewById(R.id.table_target);
234 | badge = new BadgeView(this, target);
235 | badge.setText("OK");
236 | badge.show();
237 |
238 | // *** test linear layout ***
239 |
240 | target = findViewById(R.id.linear_group_target);
241 | badge = new BadgeView(this, target);
242 | badge.setText("OK");
243 | badge.show();
244 |
245 | // *** test relative layout ***
246 |
247 | target = findViewById(R.id.relative_group_target);
248 | badge = new BadgeView(this, target);
249 | badge.setText("OK");
250 | badge.show();
251 |
252 | // *** test frame layout ***
253 |
254 | target = findViewById(R.id.frame_group_target);
255 | badge = new BadgeView(this, target);
256 | badge.setText("OK");
257 | badge.show();
258 |
259 | // *** test table layout ***
260 |
261 | target = findViewById(R.id.tablerow_group_target);
262 | badge = new BadgeView(this, target);
263 | badge.setText("OK");
264 | badge.show();
265 |
266 | }
267 |
268 | private static class BadgeAdapter extends BaseAdapter {
269 | private LayoutInflater mInflater;
270 | private Context mContext;
271 | private static final int droidGreen = Color.parseColor("#A4C639");
272 |
273 | public BadgeAdapter(Context context) {
274 | mInflater = LayoutInflater.from(context);
275 | mContext = context;
276 | }
277 |
278 | public int getCount() {
279 | return DATA.length;
280 | }
281 |
282 | public Object getItem(int position) {
283 | return position;
284 | }
285 |
286 | public long getItemId(int position) {
287 | return position;
288 | }
289 |
290 | public View getView(int position, View convertView, ViewGroup parent) {
291 | ViewHolder holder;
292 |
293 | if (convertView == null) {
294 | convertView = mInflater.inflate(android.R.layout.simple_list_item_2, null);
295 | holder = new ViewHolder();
296 | holder.text = (TextView) convertView.findViewById(android.R.id.text1);
297 | holder.badge = new BadgeView(mContext, holder.text);
298 | holder.badge.setBadgeBackgroundColor(droidGreen);
299 | holder.badge.setTextColor(Color.BLACK);
300 | convertView.setTag(holder);
301 | } else {
302 | holder = (ViewHolder) convertView.getTag();
303 | }
304 |
305 | holder.text.setText(DATA[position]);
306 |
307 | if (position % 3 == 0) {
308 | holder.badge.setText(String.valueOf(position));
309 | holder.badge.show();
310 | } else {
311 | holder.badge.hide();
312 | }
313 |
314 |
315 | return convertView;
316 | }
317 |
318 | static class ViewHolder {
319 | TextView text;
320 | BadgeView badge;
321 | }
322 | }
323 |
324 | }
--------------------------------------------------------------------------------