GithubHelp home page GithubHelp logo

morristech / linker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gaineyj0349/linker

0.0 1.0 0.0 640 KB

Lightweight android library for highlighting sections of a textview, with optional callbacks.

License: MIT License

Java 100.00%

linker's Introduction

Linker

Lightweight android library for highlighting Strings inside of a textview (ignoring case), with optional callbacks. Android Arsenal alt text

Language: Java

MinSDK: 17

JavaDocs: www.gainwisetech.com/javadocs/Linker

To bring into your android project implement the artifact:

In the Project level build.gradle

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

In the App level build.gradle

       dependencies {
	        implementation 'com.github.Gaineyj0349:Linker:1.2'
	}

How to use:

1 - Construct a Linker object with a textview:

    	Linker linker = new Linker(textView);

2 - Add an array or a list of strings to be highlighted within the textview's text:

        ArrayList<String> list = new ArrayList<>();
        list.add("hello");
        list.add("world");
        linker.addStrings(list);

AND/OR

        String[] words = new String[]{"One", "Two", "Three"};
        linker.addStrings(words);

3 - Add a callback: (this is optional):

       linker.setListener(new LinkerListener() {
            @Override
            public void onLinkClick(String charSequenceClicked) {
            
                // charSequenceClicked is the word that was clicked
                
                Toast.makeText(MainActivity.this, charSequenceClicked, Toast.LENGTH_SHORT).show();
            }
        });

4 - Call the linker's update method to commit customization and rollout the setup.:

    	linker.update();

You always have the option to add Strings to the linker object, just make sure you call the update method after to refresh the spans.

	linker.addStrings("yoda");
	linker.update();

If you need a fresh slate with same linker object just call

       linker.clearLinksList()

You can customize the links also:

1 - Customize all the link colors:

      linker.setAllLinkColors(Color.BLUE);

2 - Customize link underlines:

      linker.setAllLinkUnderline(false);

3 - If you wish to customize a color or underline setting for a certain string (note the string must already be added to the linker):

      linker.setLinkColorForCharSequence("world", Color.MAGENTA);
      linker.setUnderlineModeForCharSequence("world", true);

4 - If you wish to use different setups for every word then you can also give the linker object a list or array of LinkProfiles:

        ArrayList<LinkProfile> profiles = new ArrayList<>();
        profiles.add(new LinkProfile("hello world",
                Color.GREEN, false));
        profiles.add(new LinkProfile("goodbye cruel world",
                Color.RED, false));
        profiles.add(new LinkProfile("Whoa awesome!",
                Color.CYAN, true));

        
        linker.addProfiles(profiles);

Just remember to call .update() after any additions to the linker object.

Note that the library will take care of subtleties like adding two of the same words, or same parts of a word. For example if "helloworld" and "hello" are two of the words added to the linker, "helloworld" will be given preference over "hello" when they are in the same span of characters. The linker will sort according to larger words first and trace all spans as it links them - avoiding the issue of duplication as well as intersecting spans.

Licensed under MIT license .

linker's People

Contributors

gaineyj0349 avatar

Watchers

 avatar

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.