Giter Site home page Giter Site logo

badger's Introduction

Icon Badger

Build Release Versions Arsenal

Badger is a generalized single purpose library for adding badges to drawables in general and menu items in particular.

sett (also set) - The earth or burrow of a badger.

Running with the Badger theme, it is all about the method sett. Home to the badger, it is comprised of many tunnels and several entrances. It is the ideal entry point to provide you with badges where mere drawables lived before.

Usage

The Badger.sett() methods add a BadgeDrawable to the original drawable. This results in a LayerDrawable with the BadgeDrawable added to the layer with id badger_drawable. If the original drawable is a LayerDrawable having a badge already set, this one gets reused instead.

Add a badge to a MenuItem

BadgeDrawable badge = Badger.sett(menuItem, badgeFactory);

Add a badge to an ImageView

BadgeDrawable badge = Badger.sett(imageView, badgeFactory);

Add a badge to a Drawable

Badger<?> badger = Badger.sett(drawable, badgeFactory);
BadgeDrawable badge = badger.badge;
drawable = badger.drawable;

The BadgeDrawable

The BadgeDrawable implements handling of alpha values and color filters for a default Drawable. Badger includes a general TextBadge with a single purpose implementation CountBadge.

The BadgeDrawable.Factory

The type of the badge itself is determined by the implementation of the BadgeDrawable.Factory supplied.

public interface Factory<T extends BadgeDrawable> {
    T createBadge();
}

The provided BadgeDrawable implementations define their own factories TextBadge.Factory and CountBadge.Factory.

The BadgeShape

The BadgeShape is a simplified version of an Android Shape to be used with TextBadge. With its scale, aspectRatio and gravity it defines the actual size and position of the badge itself.

BadgeShape itself provides factories for circle, square, oval, rect, round-rect and round-square.

Example

BadgeShape.oval(1f, 2f, Gravity.BOTTOM) // scale = 1 | aspectRatio = 2
BadgeShape.square(1f, Gravity.NO_GRAVITY, .5f) // scale = 1 | radiusFactor = 0.5
BadgeShape.circle(.5f, Gravity.END | Gravity.TOP) // scale = 0.5

scale

The scale determines the actual size of the badge drawable relative to the size of the original drawable.

aspectRatio

The aspectRatio determines the actual shape of the badge itself. It is the ratio between width and height. A value bigger than 1 makes the badge wider than high, a value smaller than 1 makes it higher than wide.

gravity

The gravity determines the actual position of the badge inside the original drawable. Layout directions are supported.

radiusFactor

The radiusFactor determines the actual radius of the circle, used to round the corners of the rectangle, relative to the radius of the inner circle of the badge.

Installation

Add the updated dependency supporting AndroidX

dependencies {
    implementation "com.github.v2rc:badger:$badgerVersion"
}

or the legacy version supporting the Support Library

dependencies {
    implementation 'berlin.volders:badger:0.2.1'
}

Shortcomings

The TextBadge only supports the RTL layout direction for Android Marshmallow and later.

License

Copyright (C) 2016 Christian Schmitz
Copyright (C) 2016 volders GmbH with <3 in Berlin

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

badger's People

Contributors

ligi avatar miquelbeltran avatar tynn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

badger's Issues

Using with glide ?

Can any one using it with glide ? Ex i want to show badge to image icon but load by Glide first ?

it doen't work on menu item

CountBadge.Factory c = new CountBadge.Factory(context, BadgeShape.circle(.5f, Gravity.END | Gravity.TOP)); c.createBadge().setCount(qnt); Badger.sett(elementoTarget, c);

doesn't work. No badge appears on item;

Set Badge on Drawable

Hi, I am trying to set badge on a drawable like this:

circleFactory = new CountBadge.Factory(this, BadgeShape.oval(1f, 2f, Gravity.BOTTOM));
Drawable drawable = new BitmapDrawable(getResources(), getCircleBitmap(bitmap));
circleFactory.createBadge().setCount(12);
Badger<?> badger = Badger.sett(drawable, circleFactory);
BadgeDrawable badge = badger.badge;
drawable = badger.drawable;
return drawable;

But the drawable is not getting created with Badge. Any suggestions?

How to Change the badge factory dynamically?

I'm trying to change the factory of the badge to increase it's size if the text goes beyond certain number of digits, in other words:
if the countBadge.getText().length() > 3
then change the factory to oval
what I've tried to do

first time setting up the badge:

CountBadge.Factory circleFactory =new CountBadge.Factory(this,
                BadgeShape.circle(.4f, Gravity.END | Gravity.TOP));
Badger.sett(imageView, coloredFactory);

and then in the imageView onClickListener

CountBadge badge = Badger.sett(imageView, null);
 if(badge.getText().length() > 3){
                    CountBadge.Factory ovalFactory = new CountBadge.Factory(
                            BadgeShape.oval(1f, 2f, Gravity.BOTTOM ),
                            Color.WHITE,
                            Color.BLACK);
                    badge = Badger.sett((ImageView) view, ovalFactory);
                }

but nothing changes when the new oval factory is used

how to set badge color ?

if i use paint.setColor(X) it change the border color. i want to set the entire badge color. how can i do this ?

Set the Badge value outside onOptionsItemSelected

Hello, first of all thanks you for your awesome library. (I'm with Kotlin)
I'm trying to make a little changes, I want to change the badge value in the activity onCreate

I got this code in onCreateOptionsMenu :

ovalSquare = CountBadge.Factory(this, BadgeShape.oval(1f, 2f, Gravity.BOTTOM))
Badger.sett(menu.findItem(R.id.profil), ovalSquare).count = badge

but to set the final value in the onCreate I got exception: variable theBadge was not initialised
onCreate Activity

@SuppressWarnings("ConstantConditions")
val theBadge: CountBadge = Badger.sett(theItem, ovalSquare)
theBadge.count = badge

Please can you help me ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.