Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8dc8c051 authored by YuanQY's avatar YuanQY
Browse files

CMFileManager: Fix the crash when the search file name includes mutiple white spaces.

    When the file name include mutiple white spaces and it fit for the search condition.
The highlight logical call Html.fromHtml will convert mutiple white spaces to one white
space (For example, the file name is "A  .mp3", after conver it will change to "A .mp3"),
the span length will less than the orginal file name. When call setSpan,
it will throw IndexOutOfBoundsException.

Change-Id: I00e26464427538de8f5f85ac8d6d009493767b1e
parent 3ae1d1d9
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -18,8 +18,8 @@ package com.cyanogenmod.filemanager.util;

import android.graphics.Color;
import android.graphics.Typeface;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.BackgroundColorSpan;
import android.text.style.StyleSpan;

@@ -131,7 +131,7 @@ public final class SearchHelper {
                        .replace("*", ".*"); //$NON-NLS-1$//$NON-NLS-2$
            Pattern pattern = Pattern.compile(query, Pattern.CASE_INSENSITIVE);
            Matcher matcher = pattern.matcher(name);
            Spannable span = (Spannable)Html.fromHtml(name);
            Spannable span =  new SpannableString(name);
            if (matcher.find()) {
                //Highlight the match
                span.setSpan(
@@ -155,7 +155,7 @@ public final class SearchHelper {
     */
    public static CharSequence getNonHighlightedName(SearchResult result) {
        String name = result.getFso().getName();
        Spannable span = (Spannable)Html.fromHtml(name);
        Spannable span = new SpannableString(name);
        span.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
        return span;
    }