1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.contacts.format;
18
19import com.android.contacts.widget.TextWithHighlighting;
20import com.android.contacts.widget.TextWithHighlightingFactory;
21
22import android.database.CharArrayBuffer;
23import android.graphics.Typeface;
24import android.text.SpannableStringBuilder;
25import android.text.style.StyleSpan;
26
27/** A factory for {@link TextWithHighlighting} that wraps its parts in italics. */
28public final class TestTextWithHighlightingFactory implements TextWithHighlightingFactory {
29    /** A {@link TextWithHighlighting} implementation that wraps its parts in italics. */
30    private final static class TestTextWithHighlighting extends SpannableStringBuilder
31            implements TextWithHighlighting {
32        @Override
33        public void setText(CharArrayBuffer baseText, CharArrayBuffer highlightedText) {
34            append(new String(baseText.data, 0, baseText.sizeCopied));
35            append(' ');
36            append(new String(highlightedText.data, 0, highlightedText.sizeCopied));
37            setSpan(new StyleSpan(Typeface.ITALIC), 0, baseText.sizeCopied, 0);
38            setSpan(new StyleSpan(Typeface.ITALIC), baseText.sizeCopied + 1,
39                    baseText.sizeCopied + 1 + highlightedText.sizeCopied, 0);
40        }
41    }
42
43    @Override
44    public TextWithHighlighting createTextWithHighlighting() {
45        return new TestTextWithHighlighting();
46    }
47}