Giter Club home page Giter Club 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.

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.