Search in sources :

Example 1 with MatchedEntry

use of com.tencent.wstt.gt.ui.model.MatchedEntry in project GT by Tencent.

the class LogSearchController method setLastEntrys.

public void setLastEntrys(LogEntry[] lastEntrys) {
    this.lastEntrys = lastEntrys;
    int buffLength = lastSearchMsg.length();
    // TODO 异步处理,解析搜索数据源,生成LastMatchedEntry数组
    // TODO 此时需要堵住UI
    lastMatchedEntryList.clear();
    for (int i = 0; i < lastEntrys.length; i++) {
        if (interrupted) {
            break;
        }
        LogEntry log = lastEntrys[i];
        String temp = log.msg.toLowerCase(Locale.CHINA);
        int start = -1;
        int end = -1;
        do {
            start = temp.indexOf(lastSearchMsg, end);
            if (start >= 0) {
                end = start + buffLength;
                MatchedEntry matched = new MatchedEntry(i, start, end);
                lastMatchedEntryList.add(matched);
            }
        } while (start >= 0);
    }
    // 这段影响到初始搜索,是否已选中最后一条匹配记录
    if (lastMatchedEntryList.size() > 0) {
        lastMatchedSeq = lastMatchedEntryList.size() - 1;
    } else {
        lastMatchedSeq = 0;
    }
}
Also used : MatchedEntry(com.tencent.wstt.gt.ui.model.MatchedEntry) LogEntry(com.tencent.wstt.gt.ui.model.LogEntry)

Example 2 with MatchedEntry

use of com.tencent.wstt.gt.ui.model.MatchedEntry in project GT by Tencent.

the class SearchLogAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LinearLayout ll;
    if (convertView == null) {
        ll = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.gt_log_search_list_item, parent, false);
    } else {
        ll = (LinearLayout) convertView;
    }
    TextView tvSeq = (TextView) ll.findViewById(R.id.log_search_list_item_seq);
    tvSeq.setText(position + ".");
    TextView tv = (TextView) ll.findViewById(R.id.log_search_list_item);
    String target = dataSet[position].msg;
    int tagStart = target.indexOf("/") + 1;
    int tagEnd = target.indexOf("(", tagStart + 1);
    int tidStart = tagEnd + 1;
    int tidEnd = target.indexOf(")", tidStart + 1);
    if (tagStart < tagEnd && tidStart < tidEnd) {
        SpannableString ss = new SpannableString(target);
        ss.setSpan(new ForegroundColorSpan(Color.argb(0xff, 0x9f, 0x9f, 0x9e)), 0, 19, // 日期浅灰色
        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ss.setSpan(new ForegroundColorSpan(Color.argb(0xff, 0xcb, 0x74, 0x18)), 20, 21, // 级别橘红色
        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ss.setSpan(new ForegroundColorSpan(Color.argb(0xff, 0xcb, 0x74, 0x18)), tagStart, tagEnd, // TAG橘红色
        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ss.setSpan(new ForegroundColorSpan(Color.argb(0xff, 0xcb, 0x74, 0x18)), tidStart, tidEnd, // 线程号橘红色
        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        // TODO 搜索字符串高亮部分处理
        if (GTLogInternal.getLastMatchedEntryList().size() > 0) {
            List<MatchedEntry> matchedList = GTLogInternal.getLastMatchedEntryList();
            for (int matchedSeq = 0; matchedSeq < matchedList.size(); matchedSeq++) {
                MatchedEntry mached = matchedList.get(matchedSeq);
                if (// 比当前显示位置远的部分不需要即时处理
                mached.posionInDataSet > position) {
                    break;
                }
                if (mached.posionInDataSet == position) {
                    ss.setSpan(new ForegroundColorSpan(Color.argb(0xff, 0x00, 0x00, 0x00)), mached.start, mached.end, // 前景色黑色
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    if (matchedSeq == GTLogInternal.getLastMatchedSeq()) {
                        ss.setSpan(new BackgroundColorSpan(Color.argb(0xff, 0xdd, 0xff, 0x43)), mached.start, mached.end, // 背景色黄色
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    } else {
                        ss.setSpan(new BackgroundColorSpan(Color.argb(0xff, 0x38, 0xad, 0x29)), mached.start, mached.end, // 背景色绿色
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }
                }
            }
        }
        tv.setText(ss);
        return ll;
    }
    // 如果无法解析,直接返回文本内容
    tv.setText(target);
    return ll;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) MatchedEntry(com.tencent.wstt.gt.ui.model.MatchedEntry) TextView(android.widget.TextView) SpannableString(android.text.SpannableString) LinearLayout(android.widget.LinearLayout) BackgroundColorSpan(android.text.style.BackgroundColorSpan)

Aggregations

MatchedEntry (com.tencent.wstt.gt.ui.model.MatchedEntry)2 SpannableString (android.text.SpannableString)1 BackgroundColorSpan (android.text.style.BackgroundColorSpan)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 LogEntry (com.tencent.wstt.gt.ui.model.LogEntry)1