Search in sources :

Example 6 with ShortcutsPojo

use of fr.neamar.kiss.pojo.ShortcutsPojo in project KISS by Neamar.

the class ShortcutsProvider method getResults.

@Override
public ArrayList<Pojo> getResults(String query) {
    ArrayList<Pojo> results = new ArrayList<>();
    int relevance;
    int matchPositionStart;
    int matchPositionEnd;
    String shortcutNameLowerCased;
    final String queryWithSpace = " " + query;
    for (ShortcutsPojo shortcut : pojos) {
        relevance = 0;
        shortcutNameLowerCased = shortcut.nameNormalized;
        matchPositionEnd = 0;
        if (shortcutNameLowerCased.startsWith(query)) {
            relevance = 75;
            matchPositionStart = 0;
            matchPositionEnd = query.length();
        } else if ((matchPositionStart = shortcutNameLowerCased.indexOf(queryWithSpace)) > -1) {
            relevance = 50;
            matchPositionEnd = matchPositionStart + queryWithSpace.length();
        } else if ((matchPositionStart = shortcutNameLowerCased.indexOf(query)) > -1) {
            relevance = 1;
            matchPositionEnd = matchPositionStart + query.length();
        }
        if (relevance > 0) {
            shortcut.setDisplayNameHighlightRegion(matchPositionStart, matchPositionEnd);
            shortcut.relevance = relevance;
            results.add(shortcut);
        }
    }
    return results;
}
Also used : ShortcutsPojo(fr.neamar.kiss.pojo.ShortcutsPojo) Pojo(fr.neamar.kiss.pojo.Pojo) ShortcutsPojo(fr.neamar.kiss.pojo.ShortcutsPojo) ArrayList(java.util.ArrayList)

Aggregations

ShortcutsPojo (fr.neamar.kiss.pojo.ShortcutsPojo)6 DataHandler (fr.neamar.kiss.DataHandler)2 ShortcutsProvider (fr.neamar.kiss.dataprovider.ShortcutsProvider)2 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 ShortcutIconResource (android.content.Intent.ShortcutIconResource)1 Bitmap (android.graphics.Bitmap)1 ShortcutRecord (fr.neamar.kiss.db.ShortcutRecord)1 Pojo (fr.neamar.kiss.pojo.Pojo)1 URISyntaxException (java.net.URISyntaxException)1