• Stars
    star
    100
  • Rank 340,703 (Top 7 %)
  • Language
    Java
  • License
    BSD 3-Clause "New...
  • Created about 9 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

Easily add @ mention functionality to your Android applications

Mentions

Circle CI codecov.io Codacy Badge

This library provides a simple and customizable away to setup @ mentions on any EditText. Here's all it takes to get started.

Usage Examples

We provide a builder through which you can setup different options for @ mentions. Here is an example:

EditText commentField = findViewById(activity, R.id.my_edit_text);

Mentions mentions = new Mentions.Builder(activity, commentField)
    .highlightColor(R.color.blue)
    .maxCharacters(5)
    .queryListener(new QueryListener() {
        void onQueryReceived(final String query) {
           // Get and display results for query.
        }
    })
    .suggestionsListener(new SuggestionsListener() {
        void displaySuggestions(final boolean display) {
          // Hint that can be used to show or hide your list of @ mentions".
        }
    })
    .build();

The library allows you to display suggestions as you see fit. Here is an example in the sample app Display Suggestions. When the user chooses a suggestion to @ mention, show it in the EditText view by:

final Mention mention = new Mention();
mention.setMentionName(user.getFullName());
mentions.insertMention(mention);

Inserting the mention will highlight it in the EditText view and the library will keep track of its offset. As the user types more text in the view, the library will update the offset and maintain the highlighting for you.

If you need to get the mentions currently shown in your EditText view (to send to your API or do further processing):

final List<Mentionable> mentions = mentions.getInsertedMentions();
for (Mentionable mention : mentions) {
    println("Position of 1st Character in EditText " + mention.getMentionOffset());
    println("Text " + mention.getMentionName())
    println("Length " + mention.getMentionLength());
}

Builder methods

highlightColor(int color)

  • After a mention is chosen from a suggestions list, it is inserted into the EditText view and the mention is highlighted with a default color of orange. You may change the highlight color by providing a color resource id.

maxCharacters(int maxCharacters)

  • The user may type @ followed by some letters. You may want to set a threshold to only consider certain number of characters after the @ symbol as valid search queries. The default value 13 characters. You may configure to any number of characters.

suggestionsListener(SuggestionsListener suggestionsListener)

  • The SuggestionsListener interface has the method displaySuggestions(final boolean display). It will inform you on whether to show or hide a suggestions drop down.

queryListener(QueryListener queryListener)

  • The QueryListener interface has the method onQueryReceived(final String query). The library will provide you with a valid query that you could use to filter and search for mentions. For example, if the user types @Tes, the callback will receive "Tes" as the query.

Adding to your application

Simply add Mentions as a gradle dependency. Distribution is done through jitpack.io.

See https://jitpack.io/com/github/percolate/mentions/ for instructions

Running Tests

The library contains unit tests written in Kotlin with Mockito and Robolectric.

To run the tests and generate a coverage, please execute the command

gradlew clean coverage

License

Open source. Distributed under the BSD 3 license. See LICENSE.txt for details.

More Repositories

1

caffeine

Speed up your Android development
Java
414
star
2

charlatan

Go Interface Mocking Tool
Go
200
star
3

redset

A Redis-backed sorted set useful for coordinating distributed work.
Python
72
star
4

ec2-security-groups-dumper

Dump your EC2 Security Groups as a CSV or JSON file
Python
70
star
5

foam

A library to quickly and easily enable multiple monitoring & support platforms for your mobile apps
Java
64
star
6

jennifer

A node.js bridge between Github pull requests and Jenkins.
CoffeeScript
50
star
7

iamer

Dump and load your AWS IAM configuration into text files
Python
48
star
8

ddldump

Dump a clean version of the DDLs of your tables, so you can version them.
Python
29
star
9

pratt-parser

A Pratt Parser implementation in Python
Python
29
star
10

jsonmatch

`jsonmatch` is a small library for diffing Python JSON dictionaries in a flexible, informative way
Python
17
star
11

bfh

A Python DSL for schema transformations
Python
11
star
12

retry

Percolate's Go retry package
Shell
10
star
13

sdic

SQL Data Integrity Checker
Python
9
star
14

fvd

Font Variation Description for JavaScript
JavaScript
9
star
15

neue

A minimal web font loader
JavaScript
7
star
16

dynamodb-create-cloudwatch-alarms

Automate the creation of DynamoDB ProvisionedThroughput Read/Write Alarms
Python
7
star
17

rds-create-freestoragespace-alarms

Automate the creation of RDS FreeStoragepace Alarms
Python
5
star
18

wordpress

Plugin for managing custom template polling for Percolate -> WordPress
CSS
2
star
19

dripconfig

A tool for doing configuration nicely
Python
2
star
20

sashay

Generates API documentation from a RAML definition
JavaScript
2
star
21

rds-create-cpu-alarms

Automatically create CPU alarms on your RDS servers.
Python
1
star