• Stars
    star
    956
  • Rank 47,818 (Top 1.0 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

:octocat: Drawable of badge.

Badge

Apache 2.0 License Release

Preview

Integration

  • Add the JitPack repository to your root build.gradle:
repositories {
    maven { url "https://jitpack.io" }
}
  • Add the dependency to your sub build.gradle:
dependencies {
    implementation "com.github.nekocode:Badge:${last-version}"
}

Badge Types

This library provides four types of badges with cliche customizations.

Type Badge Type Badge
TYPE_NUMBER number TYPE_ONLY_ONE_TEXT single
TYPE_TWO_TEXT two TYPE_TWO_TEXT_COMPLEMENTARY complementary

Attributes

Usage

The above screenshot's example:

final BadgeDrawable drawable =
        new BadgeDrawable.Builder()
                .type(BadgeDrawable.TYPE_NUMBER)
                .number(9)
                .build();

final BadgeDrawable drawable2 =
        new BadgeDrawable.Builder()
                .type(BadgeDrawable.TYPE_ONLY_ONE_TEXT)
                .badgeColor(0xff336699)
                .text1("VIP")
                .build();

final BadgeDrawable drawable3 =
        new BadgeDrawable.Builder()
                .type(BadgeDrawable.TYPE_WITH_TWO_TEXT_COMPLEMENTARY)
                .badgeColor(0xffCC9933)
                .text1("LEVEL")
                .text2("10")
                .padding(dp2px(2), dp2px(2), dp2px(2), dp2px(2), dp2px(2))
                .strokeWidth(dp2px(1))
                .build();

final BadgeDrawable drawable4 =
        new BadgeDrawable.Builder()
                .type(BadgeDrawable.TYPE_WITH_TWO_TEXT)
                .badgeColor(0xffCC9999)
                .text1("TEST")
                .text2("Pass")
                .build();

final BadgeDrawable drawable5 =
        new BadgeDrawable.Builder()
                .type(BadgeDrawable.TYPE_NUMBER)
                .number(999)
                .badgeColor(0xff336699)
                .build();

The above drawable4 BadgeDrawable has set a number that too large to show, in this case, it will be replaced with "..." for showing. And then you can use toSpannable() for converting the drawable to SpannableString without setting its drawing bounds. It has already took internal measure.

SpannableString spannableString =
        new SpannableString(TextUtils.concat(
                "TextView ",
                drawable.toSpannable(),
                " ",
                drawable2.toSpannable(),
                " ",
                drawable3.toSpannable(),
                " ",
                drawable4.toSpannable(),
                " ",
                drawable5.toSpannable()
        ));

textView.setText(spannableString);

If the drawable's bounds was setted by manual or content view. It will auto cut the text to adjust the bounds' width. Look like:

You can also use the badge drawable for ImageView and other more view.

More Repositories

1

CameraFilter

📷 Realtime camera filters on android.
Java
2,129
star
2

create-android-kotlin-app

Create kotlin android project with one line of command.
Kotlin
1,596
star
3

Emojix

Implementation of iOS style emoji on android.
Java
586
star
4

MusicVisualization

Some music visualization demos on android.
Java
488
star
5

Murmur

📻 A third-party android client of DoubanFM.
Kotlin
453
star
6

DividerDrawable

Help to layout and draw dividers on android views.
Java
452
star
7

ResourceInspector

A debug tool to inspect used layout files of current Activity.
Java
349
star
8

Meepo

A router generator on android, similar to retrofit.
Java
316
star
9

android-parcelable-intellij-plugin-kotlin

Plugin which generates Android Parcelable boilerplate code for kotlin's class.
Java
300
star
10

TriangulationDrawable

Low Ploy Triangulation Animation on Android.
Java
255
star
11

Items

Generate data-view-binding adapters of android recycler view.
Kotlin
252
star
12

JarFilterPlugin

Help exclude classes before building the JAR into Android DEX archives.
Kotlin
222
star
13

ToolbarIndicator

A toolbar indicator for android, likes twitter's.
Java
221
star
14

tornaREST

A simple RESTful Web Service built with Tornado.
Python
212
star
15

doubanfm-py

📻 豆瓣 FM 第三方红心频道播放器
Python
132
star
16

zhihuSayHi

[Unmaintained] Say Hi to your new followers in Zhihu.
Python
118
star
17

RxActivityResult

This is a library that can help you to receive results from startActivityForResult() as an Observable.
Java
76
star
18

wx_sniffer

抓取微信公众号文章阅读数、点赞数
Python
74
star
19

MethodTracerCli

A command-line interface of Android Studio's method tracer.
Java
61
star
20

use-shared-state

React hook for sharing state or notifying event between components. Just like the widget controller in Flutter.
TypeScript
58
star
21

weixin_vote

使用 Tornado 开发的微信公众平台投票系统
JavaScript
44
star
22

h5pay-flutter

A H5/HTML5 payment (such as Alipay, WeChat-Pay) plugin for flutter.
Dart
42
star
23

ASM-Systrace

A plugin to inject tracing code to specified methods.
Java
37
star
24

GradleImportAar

This project demonstrates how to import aar libs to a pure java gradle module.
Kotlin
32
star
25

v2ray-docker

Docker image of v2ray(ws + tls) & caddy2.
HTML
26
star
26

nekocode.cn

The repository that hosted the source files of nekocode.cn
TypeScript
26
star
27

Websocket-Adb-Forward

Create websocket connection between your mobile and computer via USB.
Java
24
star
28

win_penetration

Penetration testing on windows(7 or 8)
PowerShell
24
star
29

codelabs-hugo-theme

A hugo theme for building codelabs website.
JavaScript
24
star
30

blur-using-textureview

Create blur effect on android by using texture view.
Java
22
star
31

gradle-dependency-graph

Visualize the dependency graph of gradle project.
TypeScript
19
star
32

project-gallery

A webpage to show the projects you have open sourced in github.
JavaScript
18
star
33

antd-dayjs-vite-plugin

A Vite port of antd-dayjs-webpack-plugin. Day.js vite plugin for Ant Design (antd).
TypeScript
18
star
34

drag-down-to-pop-flutter

A page transition which supports drag-down-to-pop gesture.
Dart
17
star
35

leetcode-solutions

My solutions of leetcode's problems.
Java
16
star
36

docker-android

Docker image for Android builds.
13
star
37

neko-gallery

A cyberpunk style gallery website for listing all your open sourced projects.
Svelte
12
star
38

Unity3D-TextureAtlasSlicer-Cocos2d-x

Simple and fast tool to import Cocos2d-x spritesheets (TextureAtlas) into Unity3D.
C#
12
star
39

nekocode.github.io

The repository to host website nekocode.cn.
HTML
11
star
40

TachieTransition

Tachie transition, written in renderscript.
Java
10
star
41

github_email_crawler

A tool for crawling emails from github.com.
TypeScript
9
star
42

resume

My personal resume.
CSS
8
star
43

Bangcle-Crypto-Wrapper

Encrypt your keys at build time using the Bangcle WhiteCrypto tools.
Java
7
star
44

finding_self_starred

寻找某人自己 Star 自己的仓库
Python
6
star
45

resty-limit-docker

An openresty/nginx based api gateway that can limit max count of connected IPs and traffic speed of network.
Shell
5
star
46

nbackdoor

A simple backdoor script on windows.
Python
4
star
47

Taskkiller

在后台静默监控并杀死指定进程的工具
C++
4
star
48

typescript-graphql-over-prisma

This example demonstrates how to build a GraphQL server over the Prisma.
TypeScript
4
star
49

DepAnPlugin

A gradle plugin to extract the bytecode and dependency information (between classes, fields and methods) of your Android project.
Kotlin
4
star
50

FScript0.15

A simple text adventure game engine.
C++
3
star
51

FScript0.2

A simple text adventure game engine.
C
2
star
52

FScriptIDE

A simple IDE for FScript 0.1x.
C++
2
star
53

wcmovie_test

「卧槽电影」公众号营销用测试游戏
Python
2
star
54

BattleBeats

A danmaku game just like 'BeatHazard'.
C++
1
star
55

svelte-ts-scss-template

Template for building applications with Svelte.
JavaScript
1
star
56

cxi

批处理 mask 位图,转换为带 alpha 的 png 图片
C++
1
star
57

caddy-iplimit

A caddy plugin for limiting the max number of connected IPs.
Go
1
star
58

vimrc

.vimrc for python dev
Vim Script
1
star
59

mqtt_test

mqtt test in python
Python
1
star
60

Hidden-Apis-Calling-Demo

It demonstrates a simple way to directly call hidden apis of android sdk.
Java
1
star